Generate Random Data for MongoDb

a Python script to generate random data to MongoDb using the Faker library for Python.

I will include some of my scripts for Elasticsearch, DynamoDB and CSV at the bottom of this post.

Dependencies:

$ pip install pymongo
$ pip install fake-factory

Python Script to Generate Data:

from pymongo import MongoClient
from faker import Factory
import time

client = MongoClient('mongodb://user:pass@host.domain.com:23325/db')
db = client.db

def create_names(fake):
    for x in range(10):
        genName = fake.first_name()
        genSurname = fake.last_name()
        genJob = fake.job()
        genCountry = fake.country()

        result = db.col1.insert_one(
            {
                'name': genName,
                'surname': genSurname,
                'job': genJob,
                'country': genCountry
                }
            )

        print 'id: ' + str(result.inserted_id) + ' name: ' + genName
        time.sleep(1)

if __name__ == '__main__':
    fake = Factory.create()
    create_names(fake)

Similar scripts to generate data to other services: