से शुरू होने वाले MongoDB संग्रह के लिए, निम्नलिखित सिंटैक्स है -
db.createCollection(‘_yourCollectionName’);
नीचे दिए गए सिंटैक्स का उपयोग करके क्वेरी डालें -
db.getCollection('_yourCollectionName').insertOne({"yourFieldName1":"yourValue1","yourFieldName2":yourValue2,............N}); आइए पहले दस्तावेजों के साथ एक संग्रह बनाएं -
> db.createCollection('_testUnderscoreCollectionDemo');
{ "ok" : 1 }
>db.getCollection('_testUnderscoreCollectionDemo').insertOne({"StudentFirstName":"John","StudentAge":23});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ccfb4a6140b992277dae0e4")
}
>db.getCollection('_testUnderscoreCollectionDemo').insertOne({"StudentFirstName":"Carol","StudentAge":21});
{
"acknowledged" : true,
"insertedId" : ObjectId("5ccfb4af140b992277dae0e5")
} खोज () विधि की मदद से संग्रह से सभी दस्तावेजों को प्रदर्शित करने के लिए क्वेरी निम्नलिखित है -
> db.getCollection('_testUnderscoreCollectionDemo').find().pretty(); यह निम्नलिखित आउटपुट देगा -
{
"_id" : ObjectId("5ccfb4a6140b992277dae0e4"),
"StudentFirstName" : "John",
"StudentAge" : 23
}
{
"_id" : ObjectId("5ccfb4af140b992277dae0e5"),
"StudentFirstName" : "Carol",
"StudentAge" : 21
}