Node.js 更新MongoDB中数组中嵌套对象数组中嵌套对象数组中的值
如何以编程方式更新表1的标题 这是一种静态方式:Node.js 更新MongoDB中数组中嵌套对象数组中嵌套对象数组中的值,node.js,mongodb,Node.js,Mongodb,如何以编程方式更新表1的标题 这是一种静态方式: { _id: ObjectId("5757646866e59fac8d1d8589"), updatedAt: ISODate("2016-06-09T02:49:09.792Z"), createdAt: ISODate("2016-06-08T00:18:48.147Z"), books: [ { name: "book1", id: "1", chapters: [
{
_id: ObjectId("5757646866e59fac8d1d8589"),
updatedAt: ISODate("2016-06-09T02:49:09.792Z"),
createdAt: ISODate("2016-06-08T00:18:48.147Z"),
books: [
{
name: "book1",
id: "1",
chapters: [
{
id: "1",
name: "CH1",
details: "Chapter 1",
tables: [
{
table : 1,
heading : 'heading 1' // update this
},
{
table: 2,
heading: 'heading 2'
}
]
}
]
}
]
}
我想做的是这样的:
db.books.update({_id: ObjectId("5757646866e59fac8d1d8589")},
{$set: {"books.0.chapters.0.tables.0.heading": "new Heading"}})
db.books.update({u id:ObjectId(“5757646866e59fac8d1d8589”),
'books.id':'1',
'books.chapters.id':'1',
'书籍.章节.表格.表格':'1'},
{$set:{}})
可能db.books.update({u id:ObjectId(“5757646866e59fac8d1d8589”),{$set:{“books.0.chapters.0.tables.0.heading:“newheading”}})
您应该澄清我们应该如何选择表1?这只是一个位置更新还是基于某些条件?只是更新了我认为的解决方案。
db.books.update({_id: ObjectId("5757646866e59fac8d1d8589"),
'books.id': '1',
'books.chapters.id':'1',
'books.chapters.tables.table':'1' },
{$set: {<what>}})