> db.createCollection("ts", { timeseries: { timeField: "time", metaField: "meta", granularity: "minutes" }})
> db.ts.insertMany([{time: new Date(), meta: {key: 2, val: 0}, val: 42, key: 1},{time: new Date(), meta: {key: 1, val: 0}, val: 43, key: 1}])
single predicate with non-consts
> db.ts.aggregate({$match: {$expr: {$lt: ["$meta.val","$val"]}}})
correctly returns both docs from the collection
two const predicates, combined with $and,
> db.ts.aggregate({$match: {$expr: {$and: [{$lt: ["$meta.val",42]}, {$eq: ["$meta.key",1]}]}}})
correctly returns one matching doc from the collection
two predicates, one of them non-const
> db.ts.aggregate({$match: {$expr: {$and: [{$lt: ["$meta.val","$val"]}, {$eq: ["$meta.key",1]}]}}})
raises error:
"errmsg" : "Failed to optimize pipeline :: caused by :: createComparisonPredicate() does not handle metadata predicates: 0xAAAB14AD4640",
"code" : 6707200
two non-const predicates, split across two $match stages
> db.ts.aggregate([{$match: {$expr: {$lt: ["$meta.val","$val"]}}}, {$match: {$expr: {$eq: ["$meta.key","$key"]}}}])
correctly returns one matching doc from the collection