如何在 MongoDB 中正确创建集合以避免“ReferenceError: 未定义”错误?
要正确创建集合,您需要在调用中使用 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" ]
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP