I have a collection like below.
"userId" : ObjectId("5c666338421aa9791982f367")
"attendance" : [
{
"attendanceTakenAt" : "2019-02-19T06:26:25.423000Z",
"day" : 19,
"hour" : 6,
"minute" : 26,
"month" : 2,
"morningAttendance" : true,
"period" : "morning",
"seconds" : 25,
"year" : 2019
},
{
"afternoonAttendance" : true,
"attendanceTakenAt" : "2019-02-19T07:00:31.019000Z",
"day" : 19,
"hour" : 7,
"minute" : 0,
"month" : 2,
"period" : "afternoon",
"seconds" : 31,
"year" : 2019
},
{
"afternoonAttendance" : false,
"attendanceTakenAt" : "2019-02-19T09:09:04.960000Z",
"day" : 20,
"hour" : 9,
"minute" : 9,
"month" : 2,
"period" : "afternoon",
"seconds" : 4,
"year" : 2019
},
{
"attendanceTakenAt" : "2019-03-01T06:24:41.474000Z",
"day" : 1,
"hour" : 6,
"minute" : 24,
"month" : 3,
"morningAttendance" : true,
"period" : "morning",
"seconds" : 41,
"year" : 2019
},
{
"afternoonAttendance" : true,
"attendanceTakenAt" : "2019-03-01T06:52:53.447000Z",
"day" : 1,
"hour" : 6,
"minute" : 52,
"month" : 3,
"period" : "afternoon",
"seconds" : 53,
"year" : 2019
},
{
"afternoonAttendance" : true,
"attendanceTakenAt" : "2019-03-07T06:58:04.483000Z",
"day" : 7,
"hour" : 6,
"minute" : 58,
"month" : 3,
"period" : "afternoon",
"seconds" : 4,
"year" : 2019
}
]
Now i need to update "afternoonAttendance": false
for "attendance.day": 7
. I tried using arrayFilters like below in mongo.
db.student_database.update({userId: ObjectId("5c666338421aa9791982f367"), rollNumber: "100"}, { $set: { "attendance.$[elem].afternoonAttendance" : false } }, {multi: true, arrayFilters: [ {"elem.day": 7, "elem.month": 3, "elem.year": 2019, "elem.period": "afternoon"} ] })
Above query works fine in MongoDB interface. but, I am not gettiing to use this query in phoenix elixir project. I am trying like below in elixir project.
filter = %{
"userId" => ObjectId("5c666338421aa9791982f367"),
"rollNumber" => "100"
}
update = %{
"$set" => %{
"attendance.$[elem].afternoonAttendance" => false
}
}
options = %{
"arrayFilters" => [%{ "elem.day" => 7, "elem.month" => 3, "elem.year" => 2019, "elem.period" => "afternoon" }]
}
Mongo.update_many(:mongo, "db_collection", filter, update, options)
Which is getting error. Please help me how to update in elixir project.