How would I go about filtering a set of records based on their child records.
Let’s say I have a collection Item that has a field to another collection Bag called bagId. I’d like to find all Items where a field on Bags matches some clause.
I.e. db.Items.find( { "where bag.type:'Paper' " }) . How would I go about doing this in MongoDB. I understand I’d have to join on Bags and then link where Item.bagId == Bag._id
I used Studio3T to convert a SQL GROUP BY to a Mongo aggregate. I’m just wondering if there’s any defacto way to do this.
-
Should I perform a data migration to simply include
Bag.typeon everyItemdocument (don’t want to get into the habit of continuously making schema changes everytime I want to sort/filterItemsbyBagfields). -
Use something like GitHub - meteorhacks/meteor-aggregate: Proper MongoDB aggregations support for Meteor (No luck with that syntax yet)
-
Grapher GitHub - cult-of-coders/grapher: Grapher: Meteor Collection Joins + Reactive GraphQL like queries I played around with this briefly and while it’s cool I’m not sure if it’ll actually solve my problem. I can use it to add
Bag.typeto every Item returned, but I don’t see how that could help me filter every item byBag.type.
Is this just one of the tradeoffs of using a NoSQL dbms? What option above is recommended or are there any other ideas?
Thanks