문서로 컬렉션을 만들자 −
> db.demo362.insertOne({"ClientName":"John","ClientProject":"School Management System"}); { "acknowledged" : true, "insertedId" : ObjectId("5e56a77454a481fef8ec7a1c") } > db.demo362.insertOne({"ClientName":"David","ClientProject":"Library Management System"}); { "acknowledged" : true, "insertedId" : ObjectId("5e56a78454a481fef8ec7a1d") } > db.demo362.insertOne({"ClientName":"Mike","ClientProject":"Event Tracker"}); { "acknowledged" : true, "insertedId" : ObjectId("5e56a7a054a481fef8ec7a1e") } > db.demo362.insertOne({"ClientName":"Carol","ClientProject":"Hospital Management System"}); { "acknowledged" : true, "insertedId" : ObjectId("5e56a7b754a481fef8ec7a1f") }
find() 메서드를 사용하여 컬렉션의 모든 문서 표시 -
> db.demo362.find();
이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : ObjectId("5e56a77454a481fef8ec7a1c"), "ClientName" : "John", "ClientProject" : "School Management System" } { "_id" : ObjectId("5e56a78454a481fef8ec7a1d"), "ClientName" : "David", "ClientProject" : "Library Management System" } { "_id" : ObjectId("5e56a7a054a481fef8ec7a1e"), "ClientName" : "Mike", "ClientProject" : "Event Tracker" } { "_id" : ObjectId("5e56a7b754a481fef8ec7a1f"), "ClientName" : "Carol", "ClientProject" : "Hospital Management System" }
다음은 여러 문서를 가져오는 쿼리입니다. -
> db.demo362.find({$or: [{"ClientName":"John"}, {"ClientProject": "Event Tracker" }]});
이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : ObjectId("5e56a77454a481fef8ec7a1c"), "ClientName" : "John", "ClientProject" : "School Management System" } { "_id" : ObjectId("5e56a7a054a481fef8ec7a1e"), "ClientName" : "Mike", "ClientProject" : "Event Tracker" }