top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How a collection is created in mongoDB ?

+1 vote
270 views
How a collection is created in mongoDB ?
posted Jun 18, 2015 by Vikram Singh

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

createCollection() command is used to create a collection within the database.
db.createCollection() is the correct syntax. createCollection() method has parameters string (collection name) and options.

A programmer can use various options (capped, autoIndexID, size and max ) while creating a collection within the database. Each option has its own significance. For example: capped field with option "true" is used for fixed-size collection. Capped collection is always associated with max size of collection by using size field.

max field tells about the maximum number of documents can be stored in a collection.

db.createCollection("testCollection", { capped : true, autoIndexID : true, size : 5142800, max : 10000 } )
is an example.

answer Jun 18, 2015 by Alok
Similar Questions
0 votes

MONGODB 3.2.8, WIREDTIGER STORAGE ENGINE
SINGLE COLLECTION HAS MORE THAN 500G, WHETHER IT NEEDS TO BE SEPARATED?

WHAT PARAMETER SHOULD BE ADJUSTED ?

+3 votes

Here I would like to explain my query a bit more.

I inserted multiple documents within a collection. Few documents have same set of keys and few of them have some extra key:value pairs . For example:
document 1 : key1 : "key1"
document 2: key1 : "key1", key2: "key2"
document 3: key1 : "key1", key2: "key2", key3 : "key3"
document 4: key1 : "key1", key3 : "key3"

Now I want to delete the documents which have key1 and key2.
What will be the command to do so ?

...