สำหรับการเขียนความเท่าเทียมกัน คุณสามารถใช้ find() ร่วมกับค่าที่ตรงกัน ให้เราสร้างคอลเลกชันที่มีเอกสาร -
> db.demo145.insertOne({"ListOfNames":["Chris","David","Mike"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e32f37bfdf09dd6d08539bb")
}
> db.demo145.insertOne({"ListOfNames":["Bob","John"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e32f384fdf09dd6d08539bc")
} แสดงเอกสารทั้งหมดจากคอลเล็กชันโดยใช้วิธี find() -
> db.demo145.find();
สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
{ "_id" : ObjectId("5e32f37bfdf09dd6d08539bb"), "ListOfNames" : [ "Chris", "David", "Mike" ] }
{ "_id" : ObjectId("5e32f384fdf09dd6d08539bc"), "ListOfNames" : [ "Bob", "John" ] } ต่อไปนี้เป็นแบบสอบถามเพื่อใช้ตัวดำเนินการ MongoDB $eq -
> db.demo145.find({"ListOfNames":"John"}); สิ่งนี้จะสร้างผลลัพธ์ต่อไปนี้ -
{ "_id" : ObjectId("5e32f384fdf09dd6d08539bc"), "ListOfNames" : [ "Bob", "John" ] }