Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MongoDB:createCollection with parameters

Tags:

mongodb

I used this comment

> db.createCollection("naveen",{capped:true,autoIndexId:true,size:53440099,max:1000});

and I got this:

{
    "note" : "the autoIndexId option is deprecated and will be removed in a future release",
    "ok" : 1
}
like image 822
naveen prasath Avatar asked Mar 06 '26 22:03

naveen prasath


1 Answers

In fact, MongoDB doesn't need to create a collection, when you insert document MongoDB will automatically create a collection for you, and also generate unique Id for each document!

Example:

db.createCollection("naveen",{capped:true,autoIndexId:true,size:53440099,max:1000}); //don't

you don't need to create a collection, you just need to insert a direct document, it's not like SQL, It's JSON.

{ name: 'john', ...}

like this, insert document without creating a collection, it automatically generates a collection for you!

db.newYear.insert({ name: 'john', age: 33, year: 2020 });
like image 154
Ericgit Avatar answered Mar 08 '26 15:03

Ericgit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!