MongoDB Atlas 使用 $in 运算符引发错误

问题描述

我使用本地版本的社区 MongoDB (v4.4) 开发了一个应用程序。现在我已经连接到 Mongo Atlas(它运行的是 4.2 版)。

我正在运行 watch 命令来创建变更流。 虽然使用我的本地设置一切正常,但使用 atlas 时出现错误

MongoError: Error validating $match value for change streams. err=ns field has bson.D value that is not string or valid MongoDb RegEx: Error parsing value [{$in [somestring1 somestring2 somestring3]}] to RegEx: Must specify $regex field

查询,分别。监视管道是

Database.watch([
    {
        "$match":{
                "ns.coll":{
                    "$in":["somestring1","somestring2","somestring3"]
                }
            }
        }
    ],{fullDocument:"updateLookup"}
)

我已将其更改为 $or 替代:


Database.watch([
        {
            "$match":{
                "$or":[
                    {"ns.coll":"somestring1"},{"ns.coll":"somestring2"},{"ns.coll":"somestring3"}
                ]
            }
        }
    ],{fullDocument:"updateLookup"}
)

这可以正常工作。 Database 是来自 nodejs 驱动程序的连接。错误调用手表后atlas服务器的立即响应。

错误也有这个属性

  ok: 0,code: 8000,codeName: 'AtlasError'

有什么问题吗?我可以/应该怎么做? 虽然解决方法有效,但我想它的性能较低。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)