Reputation: 1369
Here is the simple piece of code to create collection.But collection is not created.
import pymongo
conn=pymongo.Connection()
db=conn["userdb"]
table=db["Books"]
COuld anyone help me out with this?
Upvotes: 7
Views: 13942
Reputation: 43884
The collection will not be created until you add data, this is since collections and even databases in MongoDB are done lazily by default.
If you wish to explicitly allocate a collection eagerly then use db.create_collection(name)
: http://api.mongodb.org/python/current/api/pymongo/database.html#pymongo.database.Database.create_collection
Upvotes: 17