ในการสร้างคอลเลกชันอย่างถูกต้อง คุณต้องใช้วัตถุ MongoDB ในการเรียกเช่น
db.createCollection("yourCollectionName"); ให้เราใช้ไวยากรณ์ข้างต้นเพื่อสร้างคอลเลกชันและเรียกใช้โดยใช้วัตถุ MongoDB -
> use sample;
switched to db sample
> db.createCollection("employeeInformation");
{ "ok" : 1 } แสดงคอลเลกชันทั้งหมดจากฐานข้อมูล 'ตัวอย่าง' ด้านบน -
> db.getCollectionNames();
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
[ "arraySizeErrorDemo", "atleastOneMatchDemo", "basicInformationDemo", "combinedAndOrDemo", "convertSQLQueryDemo", "copyThisCollectionToSampleDatabaseDemo", "countOrSizeDemo", "distinctOnMultipleFieldsDemo", "documentWithAParticularFieldValueDemo", "employee", "employeeInformation", "findListOfIdsDemo", "findMimimumElementInArrayDemo", "findSubstring", "getAllRecordsFromSourceCollectionDemo", "getElementWithMaxIdDemo", "insertDocumentWithDateDemo", "internalArraySizeDemo", "keepTwoColumnsUniqueDemo", "largestDocumentDemo", "makingStudentInformationClone", "nestedArrayDemo", "oppositeAddToSetDemo", "prettyDemo", "projectionAnElementDemo", "replacingEntireDocumentDemo", "returnOnlyUniqueValuesDemo", "searchInInnerDemo", "selectItemDemo", "selectWhereInDemo", "sourceCollection", "specificFieldDemo", "studentInformation", "sumOfValueDemo", "sumTwoFieldsDemo", "truncateDemo", "updateFieldIfValueIsGreaterDemo", "updateInformation", "updateSubObjectDemo", "userInformation" ]