
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
Query MongoDB collection starting with _?
For MongoDB collection beginning with_, following is the syntax −
db.createCollection(‘_yourCollectionName’);
Insert query using below syntax −
db.getCollection('_yourCollectionName').insertOne({"yourFieldName1":"yourValue1","yourFieldName2":yourValue2,............N});
Let us first create a collection with documents −
> db.createCollection('_testUnderscoreCollectionDemo'); { "ok" : 1 } >db.getCollection('_testUnderscoreCollectionDemo').insertOne({"StudentFirstName":"John","StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb4a6140b992277dae0e4") } >db.getCollection('_testUnderscoreCollectionDemo').insertOne({"StudentFirstName":"Carol","StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5ccfb4af140b992277dae0e5") }
Following is the query to display all documents from a collection with the help of find() method −
> db.getCollection('_testUnderscoreCollectionDemo').find().pretty();
This will produce the following output −
{ "_id" : ObjectId("5ccfb4a6140b992277dae0e4"), "StudentFirstName" : "John", "StudentAge" : 23 } { "_id" : ObjectId("5ccfb4af140b992277dae0e5"), "StudentFirstName" : "Carol", "StudentAge" : 21 }
- Related Articles
- MongoDB query to rename a collection?
- How do I query a MongoDB collection?
- MongoDB query to find last object in collection?
- MongoDB: How to query a collection named “version”?
- MongoDB query to remove entire array from collection?
- MongoDB query to retrieve records from a collection named with letters and numbers
- Get the maximum mark records from a collection with documents in MongoDB query
- MongoDB query to update each field of documents in collection with a formula?
- MongoDB query to remove entire data from a collection
- MongoDB query for capped sub-collection in an array
- MongoDB query to pull array element from a collection?
- MongoDB collection query to exclude some fields in find()?
- MongoDB query to update a specific document from a collection
- MongoDB concurrent update with sub collection?
- MongoDB query to find a specific city record from a collection

Advertisements