Here is an example of my data:
{
"_id" : ObjectId("6144f74c066fee820d28b34f"),
"Login" : ISODate("2021-09-16T21:09:00.000Z"),
"DiaryNotes" : [
{
"Message" : "Metus tincidunt ultricies.",
"Timestamp" : ISODate("1922-07-29T01:42:00.000Z")
},
{
"Message" : "Ligula, eleifend ultrices, fames in, est aliquam ex congue.",
"Timestamp" : ISODate("2022-01-09T12:48:00.000Z")
}
],
}
The following query works for Mongo 4.2+:
db.getCollection('Surveys').updateMany({},
[
{
$set: {
DiaryNotes: {
$filter: {
input: "$DiaryNotes",
cond: { $lt: [ "$Login", "$$this.Timestamp" ] }
}
}
}
}
])
But if this query is executed against a CosmosDB service using Mongo 4.0 API I get an error: "Expected type object but found array." I think this is because Mongo 4.0 does not support update aggregation pipelines.
Can this query be refactored in a way that supports Mongo 4.0?