【发布时间】:2014-01-11 15:50:29
【问题描述】:
我有一个如下的数据库结构:
{
"_id" : 1,
"comments" : [
{
"_id" : 2,
"content" : "xxx"
}
]
}
我在 cmets 字段中更新了一个新的子文档。没关系。
db.test.update(
{"_id" : 1, "comments._id" : 2},
{$push : {"comments.$.comments" : {_id : 3, content:"xxx"}}}
)
之后的数据库结构:
{
"_id" : 1,
"comments" : [
{
"_id" : 2,
"comments" : [
{
"id" : 3,
"content" : "xxx"
}
],
"content" : "xxx"
}
]
}
但是当我在 _id 为 3 的注释字段中更新一个新的子文档时,出现错误:
db.test.update(
{"_id" : 1, "comments.comments.id" : 3},
{$push : {"comments.comments.$.comments" : {id : 4, content:"xxx"}}}
)
错误信息:
无法使用字符串字段名称附加到数组:cmets
【问题讨论】:
标签: mongodb