Find latest record for based on multiple ID's using Meteor

469 views Asked by At

I have a collection in mongodb which has the following format:

{
   parentId: "12345akNu",
   createdAt: "2018-12-02",
   complete: false
}

I would like to find all most recent records for a set of parentId's which are not completed. I currently have this query to find all records, but I cannot figure out how to only get the latest records.

collection.find({ parentId: { $in: list_of_ids }, completed: false});

For a single records this is the case of using findOne with a sort on {createdAt: -1}, but I need to run this in one query for multiple records if possible.

Update

As this has been suggested to be closed I am updating and clarifying the query.

This is for a Meteor application which (on the client side) has a limited interface to the mongodb drivers, supporting only find and findOne. It would be ideal if this could be achieved with only those calls.

0

There are 0 answers