Mongodb subset Query

  mongodb, question

For example, the following collention:

  1. { test: [1,2,3] }
  2. { test: [1,3] }
  3. { test: [2] }
  4. { test: [3,4] }
    How to find the test array is the result of another subset of arrays [1,2,3]?
    Similar to $all query, but opposite to $all.
    DB. COLL. FIND ({$ SUBSET: [1, 2, 3]}}) should get several other results besides 4.

db.test.insert({test:[1,2,3]}); db.test.insert({test:[1,2]}); db.test.insert({test:[1]}); db.test.insert({test:[1,2,4]}); db.test.insert({test:[1,2,3,4]}); db.test.insert({test:[4]}); //This sentence returns doc with elements that are not in the set [1,2,3] db.test.find({test:{$elemMatch:{$nin:[1,2,3]}}}) //This sentence is contrary to the above, and returns doc with all elements in the set [1,2,3] db.test.find({test:{$not:{$elemMatch:{$nin:[1,2,3]}}}})

请输入图片描述