How to create a collection correctly in MongoDB to avoid “ReferenceError: Not defined” error?

MongoDBDatabaseBig Data Analytics

To create a collection correctly you need to use a MongoDB object in call i.e.

db.createCollection("yourCollectionName");

Let us implement the above syntax in order to create a collection and call it using a MongoDB object −

> use sample;
switched to db sample

> db.createCollection("employeeInformation");
{ "ok" : 1 }

Display all the collections from the above ‘sample’ database −

> db.getCollectionNames();

This will produce the following output −

[
   "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"
]
raja
Published on 22-May-2019 12:24:58
Advertisements