문서로 컬렉션을 만들자 −
> db.demo707.insertOne(
... {
... id:101,
... "serverInformation":
... [
... {
... "IP":"192.56.34.3",
... "Status":"Active"
... },
... {
... "IP":"192.56.36.4",
... "Status":"Inactive"
... }
... ]
... }
... );
{
"acknowledged" : true,
"insertedId" : ObjectId("5ea6f852551299a9f98c93c8")
} find() 메서드를 사용하여 컬렉션의 모든 문서 표시 -
> db.demo707.find();
이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : ObjectId("5ea6f852551299a9f98c93c8"), "id" : 101, "serverInformation" : [ { "IP" : "192.56.34.3", "Status" : "Active" }, { "IP" : "192.56.36.4", "Status" : "Inactive" } ] } 다음은 활성 서버를 비활성 상태로 설정하는 쿼리입니다 -
>db.demo707.update({"serverInformation.IP":"192.56.34.3"},{$set:{"serverInformation.$.Status":"Inactive"}});
WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 }) find() 메서드를 사용하여 컬렉션의 모든 문서 표시 -
> db.demo707.find();
이것은 다음과 같은 출력을 생성합니다 -
{ "_id" : ObjectId("5ea6f852551299a9f98c93c8"), "id" : 101, "serverInformation" : [ { "IP" : "192.56.34.3", "Status" : "Inactive" }, { "IP" : "192.56.36.4", "Status" : "Inactive" } ] }