如何在 MongoDB 中正确创建集合以避免出现"ReferenceError: Not Defined"错误?
mongodbdatabasebig data analytics
要正确创建集合,您需要在调用中使用 MongoDB 对象,即:
db.createCollection("yourCollectionName");
让我们实现上述语法,以便创建一个集合并使用 MongoDB 对象 − 调用它。
> use sample;
switched to db sample
> db.createCollection("employeeInformation");
{ "ok" : 1 }
显示上述 ‘sample’ 数据库中的所有集合 −
> 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" ]

