我基本上在mongo中使用$ all运算符,我得到的输入可能是数组或单个元素,如下所示。那么如何使用下划线将所有元素放在一个数组中,然后
userId = 'a';
userIds = ['a', 'b', 'c'];
otherId = ['a'] or 'a';
searchArray = [userId, userIds, otherId]
db.collections.find({userIds: {$all: searchArray}})
您可以使用并集,只要它们是数组即可。
_.union(arrays)
var userId = ['a'],
userIds = ['a', 'b', 'c'];
otherId = ['a'],
searchArray = _.union(userId, userIds, otherId);
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句