草庐IT

setIntersection

全部标签

mongodb - $setIntersection 失败,子文档数组不在集合中

考虑以下文档:{"item1":[{"a":1,"b":2}],"item2":["a","b"]}以下查询:db.test.aggregate([{"$project":{"items":{"$setIntersection":["$item1","$item2"]}}}])返回预期结果:{"_id":ObjectId("5710785387756a4a75cbe0d1"),"a":[]}如果文档看起来像这样:{"item2":["a","b"]}然后:db.test.aggregate([{"$project":{"a":{"$setIntersection":["$item2",