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?
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With