_로 시작하는 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")
} 다음은 find() 메서드를 사용하여 컬렉션의 모든 문서를 표시하는 쿼리입니다. -
> db.getCollection('_testUnderscoreCollectionDemo').find().pretty(); 이것은 다음과 같은 출력을 생성합니다 -
{
"_id" : ObjectId("5ccfb4a6140b992277dae0e4"),
"StudentFirstName" : "John",
"StudentAge" : 23
}
{
"_id" : ObjectId("5ccfb4af140b992277dae0e5"),
"StudentFirstName" : "Carol",
"StudentAge" : 21
}