我正在学习 MongoDB 的一些基础知识。我有一个来自 MongoDB 教程的文档:
>db.post.insert([
{
title: 'MongoDB Overview',
description: 'MongoDB is no sql database',
by: 'tutorials point',
url: 'http://www.tutorialspoint.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 100
},
{
title: 'NoSQL Database',
description: 'NoSQL database doesn't have tables',
by: 'tutorials point',
url: 'http://www.tutorialspoint.com',
tags: ['mongodb', 'database', 'NoSQL'],
likes: 20,
comments: [
{
user:'user1',
message: 'My first comment',
dateCreated: new Date(2013,11,10,2,35),
like: 0
}
]
}
])
Run Code Online (Sandbox Code Playgroud)
如何在现有文档中插入新评论?谢谢
你必须使用 $push
db.coll.update({"title" : "NoSQL Database"},{$push:{"comments":{
"user":'user2',
"message": 'My second comment',
"dateCreated": new Date(2013,11,10,2,35),
"like": 0
}}})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4198 次 |
| 最近记录: |