Retrieve records that are not linked via relation

Hi!

I’m trying to lookup data that is not linked via a relation. e.g. I have Cashup records that each have n number of Order records linked via a relation. I’m trying to get a list of any Orders in the system that have not been included in a Cashup.

Below is dirty little query that I run in mongo to get what I want, but I’d like to surface this in my app - I just can’t seem to translate this into a query using the js sdk.

Does anyone know if something like this is possible?

const cashups = db.getCollection("_Join:orders:Cashup").find().toArray()
const orderIds = cashups.map(cashup => cashup.relatedId )
const orders = db.Order.find({_id: {$nin: orderIds}, paymentStatus: "PAID"}).sort({"_created_at": 1})

Thanks!

I believe you will have to use aggregate for that: JavaScript Developers Guide | Parse

Thanks @davimacedo. I’ll take a look at that.