- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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
MongoDB exact array matching
For exact array matching, simply use find() in MongoDB. Let us create a collection with documents −
> db.demo300.insertOne({"Values":[100,200,400]}); { "acknowledged" : true, "insertedId" : ObjectId("5e4d69d05d93261e4bc9ea4d") } > db.demo300.insertOne({"Values":[500,700,900,1000]}); { "acknowledged" : true, "insertedId" : ObjectId("5e4d69dd5d93261e4bc9ea4e") } > db.demo300.insertOne({"Values":[340,670,450,500]}); { "acknowledged" : true, "insertedId" : ObjectId("5e4d69eb5d93261e4bc9ea4f") }
Display all documents from a collection with the help of find() method −
> db.demo300.find();
This will produce the following output −
{ "_id" : ObjectId("5e4d69d05d93261e4bc9ea4d"), "Values" : [ 100, 200, 400 ] } { "_id" : ObjectId("5e4d69dd5d93261e4bc9ea4e"), "Values" : [ 500, 700, 900, 1000 ] } { "_id" : ObjectId("5e4d69eb5d93261e4bc9ea4f"), "Values" : [ 340, 670, 450, 500 ] }
Here is the query to MongoDB array matching −
> db.demo300.find({"Values" : [ 340, 670, 450, 500 ]});
This will produce the following output −
{ "_id" : ObjectId("5e4d69eb5d93261e4bc9ea4f"), "Values" : [ 340, 670, 450, 500 ] }
- Related Articles
- Update field in exact element array in MongoDB?
- MongoDB query for documents matching array, irrespective of elements order
- MongoDB query for exact match
- Search for documents matching first item in an array with MongoDB?
- How to get the matching document inside an array in MongoDB?
- Update an array element matching a condition using $push in MongoDB
- MongoDB query to find matching documents given an array with values?
- Matching an array field that contains any combination of the provided array in MongoDB?
- Find the exact match in array without using the $elemMatch operator in MongoDB?
- How to find exact Array Match with values in different order using MongoDB?
- MongoDB query to update an array element matching a condition using $push?
- MongoDB Aggregate JSON array field for the matching field of other collection?
- Matching MongoDB collection items by id?
- Display the undefined and exact MongoDB document records
- Aggregate a $slice to get an element in exact position from a nested array in MongoDB?

Advertisements