Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> MongoDB

การสืบค้นอาร์เรย์ของสตริงซ้อนใน MongoDB

ใช้ Dot Notation สำหรับอาร์เรย์ซ้อน

สามารถสืบค้นค่าในอาร์เรย์ที่ซ้อนอยู่ในออบเจกต์ได้โดยใช้ dot notation ตรงไปตรงมา

> db.nestedStringDemo.insertOne({ "CustomerName": "John", "CustomerOtherDetails": [ { "Age": 29, "CountryName": "US" }, { "CompanyName": "Amazon", "Salary": 150000, "ProjectName": ["Online Library Management System", "Pig Dice Game"] } ] });

คำสั่งค้นหา ProjectName = "Chat Application":

> db.nestedStringDemo.find({"CustomerOtherDetails.ProjectName": "Chat Application"}).pretty();

ผลลัพธ์คืนเอกสารที่มีโปรเจกต์ชื่อ "Chat Application" ในอาร์เรย์ซ้อน