
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 ] }
Advertisements