我有一系列教室,我想为特定学生插入一本新书。我正在使用pymongo和mongodb。
{
"teacher": "teachername",
"room": 102,
"students": [
{
"name": "john",
"age": 21,
"books": [
{
"title": "algebra",
"pages": 300,
"author": "Jkrowling"
}
]
}
]
}
答案 0 :(得分:2)
你的答案
db.collection.update(
{'students.name' : 'john'},
{$push : {'students.$.books':
{
"title" : "new book",
"pages" : 3000,
"author" : "Me"
}
}
});