
- 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 query for exact match
For exact match, you can use $exists that checks for a match. Let us create a collection with documents −
> db.demo290.insertOne({"ListOfName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e4c0c9e5d93261e4bc9ea2d") } > db.demo290.insertOne({"ListOfName":["Chris","David"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e4c0cb05d93261e4bc9ea2e") }
Display all documents from a collection with the help of find() method −
> db.demo290.find();
This will produce the following output −
{ "_id" : ObjectId("5e4c0c9e5d93261e4bc9ea2d"), "ListOfName" : "Chris" } { "_id" : ObjectId("5e4c0cb05d93261e4bc9ea2e"), "ListOfName" : [ "Chris", "David" ] }
Here is the query for exact match of a value −
> db.demo290.find({$and: [{'ListOfName.0': {$exists: false}}, {"ListOfName": 'Chris'}]});
This will produce the following output −
{ "_id" : ObjectId("5e4c0c9e5d93261e4bc9ea2d"), "ListOfName" : "Chris" }
- Related Articles
- MongoDB query for exact match on multiple document fields
- How to find exact Array Match with values in different order using MongoDB?
- Find the exact match in array without using the $elemMatch operator in MongoDB?
- Does aggregation query with $match works in MongoDB?
- MySQL select for exact case sensitive match with hyphen in records
- MongoDB exact array matching
- MongoDB query to match and remove element from an array?
- MongoDB query (aggregation framework) to match a specific field value
- MongoDB query to match documents that contain an array field
- MongoDB query to collectively match intersection of documents against a field
- MongoDB query for array concatenation?
- How to compare two columns in an R data frame for an exact match?
- MongoDB query for ranking / search count?
- MongoDB query for a single field
- Query MongoDB for a nested search

Advertisements