[英]MongoDB not returning all results with find $in
I have a simple query to find multiple documents matching a field jId
. 我有一个简单的查询来查找与字段
jId
匹配的多个文档。 Right now there are just 2 documents. 现在只有2个文档。 Using
node-mongodb-native
and calling find
with an $in
flag limits it to only one though: 使用
node-mongodb-native
并使用$in
标志调用find
可以将它限制为一个:
let collection = db.collection('documents')
// Without $in, both are returned
collection
.find()
.toArray((err, docs) => {
docs.map((doc) => doc.jId)) // Gives ['j-04e347','j-548240']
})
// With $in, only one is returned
collection
.find({ 'jId': { '$in': [ 'j-04e347',' j-548240' ] } })
.toArray((err, docs) => {
docs.map((doc) => doc.jId)) // Gives ['j-04e347']
})
Is this a bug, or am I using the $in
operator incorrectly, or does the node-mongodb-native
package not support this? 这是一个错误,还是我错误地使用了
$in
运算符,或者node-mongodb-native
软件包不支持此功能?
If $in
is not usable, is there another way to achieve the same effect? 如果
$in
不可用,是否还有另一种方法可以达到相同的效果?
There was an extra space getting included: ' j-548240'
instead of 'j-548240'
. 包括了一个额外的空间:
' j-548240'
而不是'j-548240'
。
Ugh. 啊。 But this does indeed work in
node-mongodb-native
. 但这确实在
node-mongodb-native
起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.