Question 16 / 50
Good to KnowMediumScenarioArrays
You need users who have both Node.js and MongoDB in a skills string array. How do you write that, and how is it different from $in?
Think about it first.
Short answer
Use $all. { skills: { $all: ['Node.js', 'MongoDB'] } } requires every listed value to be present. $in matches if any value is present.
Why?
For an array of primitives, membership is just { skills: 'Node.js' }. $all is the AND of membership tests. $in is the OR. If skills is an array of objects, $all does not replace $elemMatch for per-element predicates.
Example
db.users.find({
skills: { $all: ["Node.js", "MongoDB"] }
})How did you do?