
- 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
Alternative of MongoDB operator $eq to get similar result
For writing an equality, you can simply use find() along with match value. Let us create a collection with documents −
> db.demo145.insertOne({"ListOfNames":["Chris","David","Mike"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e32f37bfdf09dd6d08539bb") } > db.demo145.insertOne({"ListOfNames":["Bob","John"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e32f384fdf09dd6d08539bc") }
Display all documents from a collection with the help of find() method −
> db.demo145.find();
This will produce the following output −
{ "_id" : ObjectId("5e32f37bfdf09dd6d08539bb"), "ListOfNames" : [ "Chris", "David", "Mike" ] } { "_id" : ObjectId("5e32f384fdf09dd6d08539bc"), "ListOfNames" : [ "Bob", "John" ] }
Following is the query to implement MongoDB operator $eq −
> db.demo145.find({"ListOfNames":"John"});
This will produce the following output −
{ "_id" : ObjectId("5e32f384fdf09dd6d08539bc"), "ListOfNames" : [ "Bob", "John" ] }
- Related Articles
- Write an equality in MongoDB without using $eq operator
- Find values with OR operator in MongoDB and format the result.?
- How to use $slice operator to get last element of array in MongoDB?
- Result of sizeof operator using C++
- Using MongoDB nested $group and $sum to get the count of stocks with similar ProductID?
- Using JSON.stringify() to display spread operator result?
- How to query MongoDB similar to “like” ?
- Match ID and fetch documents with $eq in MongoDB in case of array?
- Can MongoDB return result of increment?
- Get the aggregated result and find the count of repeated values in different MongoDB\ndocuments
- Accumulate the result of applying the operator to all elements in Numpy
- Remove document whose value is matched with $eq from a MongoDB collection?
- How to implement MongoDB $or operator
- MongoDB findById returning a list of documents instead of a single result? How to get only a single document?
- MongoDB: Find name similar to Regular Expression input?

Advertisements