gpt4 book ai didi

javascript - "Unrecognized logical operator: $in"Mongo.collection 更新

转载 作者:行者123 更新时间:2023-11-29 23:43:56 25 4
gpt4 key购买 nike

我收到这个错误:

"Unrecognized logical operator: $in"

在使用这个查询时:

this.update(
{}, {
$pull: {
words: {
$in:['string', 'string1']
}
}
}, {
multi: true
});

我在客户端中扩展 Mongo.Collection 的 es6 类中调用,到目前为止所有其他内容(插入、删除)都有效,我没有以任何方式修改更新方法。该系列是一个 local collection以这种方式声明:

WordsList = new WordCollection('words', {connection: null});)

查询与文档here 中的示例非常相似实际上,我也可以在控制台上尝试重新创建此示例时重现相同的错误。

I'm using Meteor 1.4.4.1 with MongoDB 3.2.12

出于某种原因我还不能确定,我可以将错误追溯到 Mongo 编译查询将其映射到逻辑运算符 ($and, $or) 而不是元素(比较查询)运算符 ($in, $eq) )

最佳答案

可以修改本地集合中的多个值,但是可以使用哪些选择器或修饰符是有限制的,因为客户端集合使用 MiniMongo,它实现了 MongoDB 功能的一个子集。

这种特殊情况是 MiniMongo 的缺点,在 $pull 表达式中使用逻辑 Matcher,如 $pull< 中的注释所示 实现:

    // XXX Minimongo.Matcher isn't up for the job, because we need
// to permit stuff like {$pull: {a: {$gt: 4}}}.. something
// like {$gt: 4} is not normally a complete selector.
// same issue as $elemMatch possibly?

(source: Meteor source code)

这是从 2013 年开始的,所以如果没有 PR,改变它的希望不大。

具体来说,匹配器只允许您使用逻辑选择器:“$and”、“$or”、“$nor”、“$where”、“$comment”。这就是为什么您不能使用 $in 的原因,它在 ELEMENT_OPERATORS 中实现。

作为解决方法(因为这只是客户端),您可以使用:

valueArray.forEach(val => WordsList.update({}, {$pull: {words: val}}, {multi: true}));

关于javascript - "Unrecognized logical operator: $in"Mongo.collection 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44610747/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com