我一直在与以下Mongo文档作斗争:
{
"name": "Fire Name",
"address": "123 Somestreet Ave",
"city": "Boston",
"state": "MA",
"zip": "02109",
"dispatchReference": "123codefromdispatch",
"created": {
"$date": "2021-02-26T12:30:41Z"
},
"lastPar": {
"$date": "2021-02-26T22:30:41Z"
},
"latitude": "-83.691407",
"longitude": "141.338391",
"par": 3,
"vehicles": [
{
"_id": "60397691c09c2fd299c40420",
"hidden": false,
"vehicleName": "Updated",
"vehicleNumber": 20,
"vehicleStatus": "Enroute",
"latitude": "-83.691407",
"longitude": "141.338391",
"par": 6,
"lastPar": "2021-02-26T22:30:41+00:00",
"members": [
{
"_id": "60397b14f2a2b10978693a47", <---- find Member with this ID
"hidden": false, <----- update this property
"rank": "firefighter",
"dateOfRank": "2021-02-26T22:49:56+00:00",
"role": "hose",
"firstName": "Reyna",
"lastName": "Casey",
"dateOfBirth": "1992-02-26T22:49:56+00:00",
"sex": "male",
"age": 29,
"dateOfExperience": 5,
"departmentLocation": "975 Pine Street, Gasquet, Montana, 1843",
"lastIncidentID": "60397b14095d4f4313fbf716",
"bpm": 120,
"vomax": "33.1",
"temp": "104.69",
"latitude": "-81.393671",
"longitude": "-78.26867",
"scba": {
"maskStatus": false,
"oxygenLevel": "low"
}
我试图写一个Mongo查询,当给定的成员。_id,将该特定成员的隐藏属性从false更新为true。因此,我需要深入到我的车辆对象数组中,并在成员数组中找到具有匹配_id的成员。
我怀疑它与$[]运算符有关,但我没有任何运气
试试这个:
db.testcollection.updateOne(
{
// Specify some condition related to "vehicles" array.
"vehicles.members._id": ObjectId("60397b14f2a2b10978693a47")
},
{
$set: {
"vehicles.$.members.$[obj].hidden": true
}
},
{
arrayFilters: [
{
"obj._id": ObjectId("60397b14f2a2b10978693a47")
}
]
}
);