특정 문서의 경우 MongoDB $in을 사용하세요. 문서로 컬렉션을 만들자 −
> 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") }
find() 메서드를 사용하여 컬렉션의 모든 문서 표시 -
> db.demo511.find();
이것은 다음과 같은 출력을 생성합니다 -
{ "_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" ] }
다음은 일치하는 문서를 찾는 쿼리입니다 -
> db.demo511.find({ "ListOfProject":{$in:["Hospital Management System","Online Shopping Cart"]}});
이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : ObjectId("5e88473a987b6e0e9d18f585"), "ListOfProject" : [ "Library Management System", "Hospital Management System" ] } { "_id" : ObjectId("5e884776987b6e0e9d18f587"), "ListOfProject" : [ "Online Shopping Cart", "Hospital Management System" ] }