I'm doing a project using MongoDb.my problem is when i create collection, i have to insert data also. but i want to create the collection without data(same as making table in mysql without data.)
1 Answer
http://docs.mongodb.org/manual/reference/method/db.createCollection/
A quick google would have revealed this.
db.createCollection("something")
Edit
The PHP method: http://php.net/manual/en/mongodb.createcollection.php
$db->createCollection("something");
4 Comments
Scuba Steve
This is an incomplete answer. The OP is asking about how to define the structure of the document before you add data.
rick
@ScubaSteve this isn't an incomplete answer. You can't define the structure of a document because it's a schemaless database. At least that was the case when I answered this in 2013 anyway.
rick
I won't be changing the answer, there is enough information for this answer to be correct and complete. OP asked how to create a collection without data, this IS the answer. What you suggested they asked "define the structure of the document before you add data" isn't possible and isn't what they asked.
Scuba Steve