
- 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
Find all collections in MongoDB with specific field?
Let us implement the above syntax in order to find all documents in MongoDB with field name “StudentFirstName”. The query is as follows −
> db.getCollectionNames().forEach(function(myCollectionName) { ... var frequency = db[myCollectionName].find({"StudentFirstName": {$exists: true}}).count(); ... if (frequency > 0) { ... print(myCollectionName); ... } ... });
This will produce the following output −
multiDimensionalArrayProjection removeKeyFieldsDemo stringOrIntegerQueryDemo
Let us verify the removeKeyFieldsDemo collection has field with name “StudentFirstName” or not. Following is the query −
> db.removeKeyFieldsDemo.find({"StudentFirstName":{$exists:true}});
This will produce the following output displaying the StudentFirstName field exist −
{ "_id" : ObjectId("5cc6c8289cb58ca2b005e672"), "StudentFirstName" : "John", "StudentLastName" : "Doe" } { "_id" : ObjectId("5cc6c8359cb58ca2b005e673"), "StudentFirstName" : "John", "StudentLastName" : "Smith" }
- Related Articles
- Update all the values of a field with a specific string in MongoDB?
- Find documents that contains specific field in MongoDB?
- Find MongoDB documents that contains specific field?
- Find the document by field name with a specific value in MongoDB?
- Return a specific field in MongoDB?
- Fetch specific field values in MongoDB
- Search by specific field in MongoDB
- MongoDB aggregation to fetch documents with specific field value?
- How to project specific elements in an array field with MongoDB?
- Loop through all MongoDB collections and execute query?
- How do I find all documents with a field that is NaN in MongoDB?
- Removing all collections whose name matches a string in MongoDB
- Project specific array field in a MongoDB collection?
- How to get all the collections from all the MongoDB databases?
- Find all the non-distinct values of a field in MongoDB?

Advertisements