gpt4 book ai didi

mongodb - 命令失败,错误 16020 (Location16020) : 'Expression $eq takes exactly 2 arguments. 1 were passed in.' on server localhost:27017

转载 作者:行者123 更新时间:2023-12-02 19:44:40 25 4
gpt4 key购买 nike

enter image description here我的代码如下

以下是我收到的错误:

Command failed with error 16020 (Location16020): 'Expression $eq takes exactly 2 arguments. 1 were passed in.' on server localhost:27017. The full response is {"ok": 0.0, "errmsg": "Expression $eq takes exactly 2 arguments. 1 were passed in.", "code": 16020, "codeName": "Location16020"}

代码

db.chats.aggregate([
{
$match: {
users: {$in: [ObjectId("5e063bcf3e484f6430ec9053")]}
}
},

{

$lookup:{
from: "users",
localField : "users",
foreignField : "_id",
as: "users"
}
},
{ $lookup: {
from: "chats.messages",
as: "last_message",
let: { id: '$_id' },
pipeline: [
{ $match: {
$expr: { $eq: [ '$$id', '$chat_id' ] }
}},
{$sort: { _id: -1 } },
{ $limit: 1 }
]
}
},
///////Fields
{
$project: {
_id: 1,
"title": 1,
"type":1,
"users._id":1,
"users.first_name":1,
"users.last_name":1

}
}

])

最佳答案

我在 Intellij 2019.3 中执行查询时遇到了同样的问题。 Intellij使用的mongo jdbc驱动程序版本是v1.7.1。我将其切换为使用 v1.6,然后查询正常执行。

您可以在“数据源和驱动程序”窗口中更改驱动程序版本,方法是单击“MongoDB”驱动程序,然后在“驱动程序文件”部分中单击“版本 1.7.1”,选择“1.6” ”,然后从下拉菜单中单击“应用”。您需要断开连接,然后重新连接,以便它使用新的驱动程序。

enter image description here

关于mongodb - 命令失败,错误 16020 (Location16020) : 'Expression $eq takes exactly 2 arguments. 1 were passed in.' on server localhost:27017,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59511861/

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