gpt4 book ai didi

mongodb - 如何在 MongoDB 中按条件更新嵌套子文档?

转载 作者:搜寻专家 更新时间:2023-10-30 23:42:53 24 4
gpt4 key购买 nike

我有以下数据结构:

// Journeys collection in MongoDB

{
"_id" : ObjectId("560feabb682290c218770110"),
"title" : "El Camino de Santiago",
"messages" : [
{
"title" : "The sun is strong!",
"text" : "Lorem ipsum and something more text goes here",
"lat" : "-34.5555555",
"lng" : "23.34455335",
"_id" : ObjectId("560feabc682290c218770111")
},
{
"title" : "The hike was great",
"text" : "Lorem ipsum and something more text goes here",
"lat" : "-34.5555555",
"lng" : "23.34455335",
"_id" : ObjectId("560feab9682290c21877010f")
}
],
"followers" : []
}

这个特定的旅程?

最佳答案

给你:

db.journeys.update({'messages.id':  ObjectId("560feab9682290c21877010f")}, {$set: {'messages.$.title': 'New Title'}});

关于mongodb - 如何在 MongoDB 中按条件更新嵌套子文档?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32925389/

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