
- 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
MongoDB: How to query a collection named “version”?
For this, use the concept of createCollection() and getCollection(). Following is the query to create a collection with name ‘version’ −
> db.createCollection('version'); { "ok" : 1 }
Let us first create a collection with documents −
> db.getCollection('version').insertOne({"VersionName":"1.0"}); { "acknowledged" : true, "insertedId" : ObjectId("5e100b47d7df943a7cec4fae") } > db.getCollection('version').insertOne({"VersionName":"1.1"}); { "acknowledged" : true, "insertedId" : ObjectId("5e100b49d7df943a7cec4faf") } > db.getCollection('version').insertOne({"VersionName":"1.2"}); { "acknowledged" : true, "insertedId" : ObjectId("5e100b4cd7df943a7cec4fb0") }
Following is the query to display all documents from a collection with the help of find() method −
> db.getCollection('version').find();
This will produce the following output −
{ "_id" : ObjectId("5e100b47d7df943a7cec4fae"), "VersionName" : "1.0" } { "_id" : ObjectId("5e100b49d7df943a7cec4faf"), "VersionName" : "1.1" } { "_id" : ObjectId("5e100b4cd7df943a7cec4fb0"), "VersionName" : "1.2" }
- Related Articles
- MongoDB query to retrieve records from a collection named with letters and numbers
- MongoDB query to rename a collection?
- How do I query a MongoDB collection?
- Query MongoDB collection starting with _?
- MongoDB query to remove entire data from a collection
- MongoDB query to pull array element from a collection?
- MongoDB query to update a specific document from a collection
- How to remove a MySQL collection named 'group'?
- MongoDB query to find last object in collection?
- MongoDB query to remove entire array from collection?
- MongoDB query to find a specific city record from a collection
- MongoDB query to add a document in an already created collection
- MongoDB collection query to exclude some fields in find()?
- How to drop a collection in MongoDB?
- MongoDB query to update each field of documents in collection with a formula?

Advertisements