Updating a field in Mongodb

Asked

Viewed 841 times

0

Considering the following structure:

{
"_id" : ObjectId("5ad69abb3630404194c80571"),
"cnpj" : 2352345234523452,
"razao_social" : "Lalala Ltda.",
"fantasia" : " "aiufhdiua Ltda.",
"dt_criacao" : ISODate("2018-04-18T01:09:15.076Z"),
"usuarios" : [ ],
"sensores" : [
    {
        "id" : 1,
        "leituras" : [ ]

    },
    {
        "id" : 2,
        "leituras" : [ ]
    }
]

}

How do I update this document with the document below in the field only sensores.id:2?

{ "latitude": 45.435435, "longitude": 120.09345493 }

Thanks in advance!

1 answer

0


Try to execute the following command on the console of the Mongo: (replace the <collection> by the right name)

db.<collection>.update({"sensores.id" : 2 }, { $set: { "sensores.$.leituras.latitude" : "45.435435", "sensores.$.leituras.longitude": "120.09345493"}})

Browser other questions tagged

You are not signed in. Login or sign up in order to post.