create collection in mongodb code example
Example 1: mongodb create collection
db.createCollection( <name>,
{
capped: <boolean>,
autoIndexId: <boolean>,
size: <number>,
max: <number>,
storageEngine: <document>,
validator: <document>,
validationLevel: <string>,
validationAction: <string>,
indexOptionDefaults: <document>,
viewOn: <string>, // Added in MongoDB 3.4
pipeline: <pipeline>, // Added in MongoDB 3.4
collation: <document>, // Added in MongoDB 3.4
writeConcern: <document>
}
)
Example 2: create collection in mongodb stack overflow
> use testdb
switched to db testdb
> db.createCollection("testcollection")
{ "ok" : 1 }
> db.getCollectionNames()
[ "system.indexes", "testcollection" ]
>