- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a collection correctly in MongoDB to avoid “ReferenceError: Not defined” error?
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" ]
Advertisements