7

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 1

6

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");

Sign up to request clarification or add additional context in comments.

4 Comments

This is an incomplete answer. The OP is asking about how to define the structure of the document before you add data.
@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.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.