Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pymongo Not creating collection in mongodb

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?

like image 376
Vindhya G Avatar asked Jul 04 '13 13:07

Vindhya G


1 Answers

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

like image 200
Sammaye Avatar answered Oct 11 '22 17:10

Sammaye