{'index': 0, 'code': 2, 'errmsg': "No array filter found for identifier 'i' in path 'Comments.$[i].Replies.$[j].Reply'"}
{'index': 0, 'code': 2, 'errmsg': "No array filter found for identifier 'i' in path 'Comments.$[i].Replies.$[j].Reply'"}
WriteError: No array filter found for identifier 'i' in path 'Comments.$[i].Replies.$[j].Reply', full error: {'index': 0, 'code': 2, 'errmsg': "No array filter found for identifier 'i' in path 'Comments.$[i].Replies.$[j].Reply'"}
我只想更新我数据中的回复。我收到这个错误。还有其他更新方式吗?
代码
article_id = "6223bf189ee543673ca35940"
comment_id = "2d1ae2a7-1488-44b0-8ba3-9e946ed8cca9"
reply_id = "c0b9d54a-416f-4598-bf7b-33be80faa5c3"
article_collection.update_one({'_id': ObjectId(article_id)},
{
'$set': {'Comments.$[i].Replies.$[j].Reply': reply},
'arrayFilters': [{'i.ID': comment_id}, {'j.ID': reply_id}]
}, upsert=False)
数据
{
"_id" : ObjectId("6223bf189ee543673ca35940"),
"Comments" : [
{
"ID" : "2d1ae2a7-1488-44b0-8ba3-9e946ed8cca9",
"User_id" : 1,
"Comment" : "Thank you for this simple explanation.",
"Date" : ISODate("2022-03-13T02:13:09.022Z"),
"Replies" : [
{
"ID" : "c0b9d54a-416f-4598-bf7b-33be80faa5c3",
"User_id" : 1,
"Reply" : "You're welcome",
"Date" : ISODate("2022-03-13T12:53:39.046Z")
}
]
}
]
}
错误消息正确提示未找到 arrayFilters。您有语法错误,需要在更新查询的选项部分添加 arrayFilters,目前在更新部分:
Update({query},{update},{options}) ,正确的是:
article_collection.update_one({'_id': ObjectId(article_id)},
{
'$set': {'Comments.$[i].Replies.$[j].Reply': reply}},
{
'arrayFilters': [{'i.ID': comment_id}, {'j.ID': reply_id}]
}, upsert=False)
WriteError: No array filter found for identifier 'i' in path 'Comments.$[i].Replies.$[j].Reply', full error: {'index': 0, 'code': 2, 'errmsg': "No array filter found for identifier 'i' in path 'Comments.$[i].Replies.$[j].Reply'"}
我只想更新我数据中的回复。我收到这个错误。还有其他更新方式吗?
代码
article_id = "6223bf189ee543673ca35940"
comment_id = "2d1ae2a7-1488-44b0-8ba3-9e946ed8cca9"
reply_id = "c0b9d54a-416f-4598-bf7b-33be80faa5c3"
article_collection.update_one({'_id': ObjectId(article_id)},
{
'$set': {'Comments.$[i].Replies.$[j].Reply': reply},
'arrayFilters': [{'i.ID': comment_id}, {'j.ID': reply_id}]
}, upsert=False)
数据
{
"_id" : ObjectId("6223bf189ee543673ca35940"),
"Comments" : [
{
"ID" : "2d1ae2a7-1488-44b0-8ba3-9e946ed8cca9",
"User_id" : 1,
"Comment" : "Thank you for this simple explanation.",
"Date" : ISODate("2022-03-13T02:13:09.022Z"),
"Replies" : [
{
"ID" : "c0b9d54a-416f-4598-bf7b-33be80faa5c3",
"User_id" : 1,
"Reply" : "You're welcome",
"Date" : ISODate("2022-03-13T12:53:39.046Z")
}
]
}
]
}
错误消息正确提示未找到 arrayFilters。您有语法错误,需要在更新查询的选项部分添加 arrayFilters,目前在更新部分:
Update({query},{update},{options}) ,正确的是:
article_collection.update_one({'_id': ObjectId(article_id)},
{
'$set': {'Comments.$[i].Replies.$[j].Reply': reply}},
{
'arrayFilters': [{'i.ID': comment_id}, {'j.ID': reply_id}]
}, upsert=False)