2

How can I find and update the field inside the data arrays

    "_id" : ObjectId("5bfe6df9777d13255bb2ad7c"),
    "program_id" : ObjectId("5b7bcc8520a2b13177b4d92e"),
    "week_id" : "2018.10.48",
    "month" : 10.0,
    "week_count" : 48.0,
    "year" : 2018.0,
    "data" : [ 
        {
            "_id" : ObjectId("5bfe6df9c1e35824dfcce39f"),
            "date" : 27.0,
            "user_ids" : [ 
                {
                    "checkin_time" : 1543400937337.0,
                    "by" : ObjectId("5bb2aa12460b5f2ef97388e6"),
                    "checkin_by" : ObjectId("5bf7dd8387550226071eda5c"),
                    "checkin_status" : 1.0,
                    "point" : 1.0
                }, 
                {
                    "checkin_time" : 1543400937337.0,
                    "by" : ObjectId("5bb453b44817792ec972c1ab"),
                    "checkin_by" : ObjectId("5be7dd8387550226071eda5c"),
                    "user_utc_checkin_time" : 1543401130940.0,
                    "user_time_zone" : "Asia/Kolkata",
                    "checkin_status" : 1.0,
                    "point" : 1.0
                }, 
                {
                    "checkin_time" : 1543400937337.0,
                    "by" : ObjectId("5bed113bcd1c075e045aa79e"),
                    "checkin_by" : ObjectId("5bed113bcd1c075e045aa79e"),
                    "user_utc_checkin_time" : 1543401594869.0,
                    "user_time_zone" : "Asia/Kolkata",
                    "checkin_status" : 1.0,
                    "point" : 1.0
                }
            ]
        }
    ]

I am using

db.collectionName.findAndUpdate(
     {"data.user_ids.checkin_by":mongoose.Types.ObjectId(a) },  
     { $set :
        { "data.user_ids.$.checkin_status":2 }
     }
   )
Nishu Tayal
  • 20,106
  • 8
  • 49
  • 101

1 Answers1

0

Try using this:

db.collectionName.update(
{"data.user_ids.checkin_by":mongoose.Types.ObjectId(a) },
{"$set":{"data.user_ids.$.checkin_status":2 }}
)
harshit raghav
  • 593
  • 2
  • 9
  • 23