I'm trying to create an aggregate query (or any query for that matter) that will only pull the most recent document version. I tried using the suggested aggregate query with $$ROOT but that throws an error and $$ROOT doesn't seem to be available from even the raw mongodb driver
Post.collection.aggregate([
{ $sort : { uuid : 1, __v: -1}},
{ $group : { _id : "$uuid", doc: {$first: "$$ROOT"}}},
{ $match: {company: company}}
], callback);
This throws an error about a field value starting with '$' is not acceptable. Any help would be appreciated.