![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Write an equality in MongoDB without using $eq operator
Let us first create a collection with documents -
> db.operatorDemo.insertOne({"StudentSubject":["MongoDB","MySQL","Java"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef94eaef71edecf6a1f6a2") } > db.operatorDemo.insertOne({"StudentSubject":["Java","C","C++"]}); { "acknowledged" : true, "insertedId" : ObjectId("5cef94faef71edecf6a1f6a3") }
Display all documents from a collection with the help of find() method -
> db.operatorDemo.find().pretty();
Output
{ "_id" : ObjectId("5cef94eaef71edecf6a1f6a2"), "StudentSubject" : [ "MongoDB", "MySQL", "Java" ] } { "_id" : ObjectId("5cef94faef71edecf6a1f6a3"), "StudentSubject" : [ "Java", "C", "C++" ] }
Following is the query for an equality without $eq operator:
> db.operatorDemo.find({StudentSubject:"MongoDB"});
Output
{ "_id" : ObjectId("5cef94eaef71edecf6a1f6a2"), "StudentSubject" : [ "MongoDB", "MySQL", "Java" ] }
Advertisements