草庐IT

setIntesection

全部标签

MongoDB setIntesection 数组的数组

我是MongoDB的新手,在使聚合交集正常工作时遇到了一些麻烦。假设我的集合中只有以下文档:{"ids":[[1,4,7,10,13],[1,3,5,7,9,11,13,15],[1,3,5,7]]}我想回去{"intersection":[1,7]}我在做:db.collection.aggregate([{$project:{intersection:{$setIntersection:"$ids"}}}])但那是回归{"intersection":[[1,4,7,10,13],[1,3,5,7,9,11,13,15],[1,3,5,7]]}我假设这是因为“$ids”被解释为一个整