Đối với các tài liệu cụ thể, hãy sử dụng MongoDB $ in. Hãy để chúng tôi tạo một bộ sưu tập với các tài liệu -
> db.demo511.insertOne({"ListOfProject":["Library Management System","Hospital
Management System"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e88473a987b6e0e9d18f585")
}
> db.demo511.insertOne({"ListOfProject":["Online Web Tracking","Library Management
System"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e884751987b6e0e9d18f586")
}
> db.demo511.insertOne({"ListOfProject":["Online Shopping Cart","Hospital Management
System"]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e884776987b6e0e9d18f587")
} Hiển thị tất cả các tài liệu từ một bộ sưu tập với sự trợ giúp của phương thức find () -
> db.demo511.find();
Điều này sẽ tạo ra kết quả sau -
{ "_id" : ObjectId("5e88473a987b6e0e9d18f585"), "ListOfProject" : [ "Library Management
System", "Hospital Management System" ] }
{ "_id" : ObjectId("5e884751987b6e0e9d18f586"), "ListOfProject" : [ "Online Web Tracking",
"Library Management System" ] }
{ "_id" : ObjectId("5e884776987b6e0e9d18f587"), "ListOfProject" : [ "Online Shopping Cart",
"Hospital Management System" ] } Sau đây là truy vấn để tìm tài liệu phù hợp -
> db.demo511.find({ "ListOfProject":{$in:["Hospital Management System","Online Shopping Cart"]}}); Điều này sẽ tạo ra kết quả sau -
{ "_id" : ObjectId("5e88473a987b6e0e9d18f585"), "ListOfProject" : [ "Library Management
System", "Hospital Management System" ] }
{ "_id" : ObjectId("5e884776987b6e0e9d18f587"), "ListOfProject" : [ "Online Shopping Cart",
"Hospital Management System" ] }