I have a defined collection in Mongo that is a list of "supported" features. In order for an item from another collection to be considered "compatible", I need to take that item's list of features and see if all of them are in the given list. I have queried the supported features collection for the list of features already and I have them in a list.
For example, my list contains [A, B, C, D, E]
If my item has [A, B]
, it should be returned, but if it has [A, B, F]
, it should not. The $in operator states:
"If the field holds an array, then the $in operator selects the documents whose field holds an array that contains at least one element that matches a value in the specified array"
The $all operator states:
"The $all operator selects the documents where the value of a field is an array that contains all the specified elements."
My problem is that the item doesn't have the full set of features for the $all command, and I don't want it to match on a single element for the $in command. My query looks something like this (because I have already retrieved the list of compatible functions from the functions collection):
db.myColl.find({"compatibility": {"$in": ["A","B","C","D","E","F"]}})
or
db.myColl.find({"compatibility": {"$all": ["A","B","C","D","E","F"]}})
what I think I need is something that effectively reverses the query and says something like this (I know it's not valid, I'm just trying to make a point):
db.myColl.find({["A","B","C","D","E","F"]: {"$all": "compatibility"}})
Any thoughts?