Skip to content

Instantly share code, notes, and snippets.

@danilochilene
Created January 29, 2014 17:19
Show Gist options
  • Save danilochilene/8692598 to your computer and use it in GitHub Desktop.
Save danilochilene/8692598 to your computer and use it in GitHub Desktop.
### Testing MongoDB mass insert with pymongo
import pymongo
mongo = pymongo.Connection('localhost')
mongo_db = mongo['test']
mongo_collection = mongo_db['masstest']
n = 1
limit = 100000
firstnames = [ "John", "Jim", "James", "Sarah", "Anna", "Maria", "Sophia", "Martin", "Nick", "Bart" ]
while n <= limit:
for name in firstnames:
insert = mongo_collection.insert({
'name': name
})
n = n +1
Result:
bicofino@ambush:~$ time python2.7 test_pymongo.py
real 1m25.385s
user 1m16.104s
sys 0m8.608s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment