Find last elem in embeded array

Hi, there
After Mongo 3.6, it supports $expr, but it seems Meteor doesn’t ; i tried $expr in Meteor1.8.1, get error “Unrecognized logical operator: $expr” (works fine in Meteor mongo), any suggestions? thanks!

For embedded arrays - Use $arrayElemAt expression with dot notation to project last element.

db.col.find({$expr: {$gt: [{"$arrayElemAt": ["$array.field", -1]}, value]}})

Minimongo only supports a limited set of native Mongo operators. It would be awesome if Tiny could give that some love! However, you can use any supported Mongo operators if you run on the server, use rawCollection() and ensure the resulting cursor is evaluated into an array.

Something like this (typing from memory, so may be awry):

const arrayOfResults = Promise.await(someCollection.rawCollection().find({$expr: {$gt: [{"$arrayElemAt": ["$array.field", -1]}, value]}}).toArray());
1 Like

thank you @robfallows, appreciate your help. i found this in your another answer. unfortunately my code is on client. i’m going to change the schema