Skip to content

Commit

Permalink
更新多条数据
Browse files Browse the repository at this point in the history
  • Loading branch information
renfufei committed Nov 13, 2017
1 parent b59b171 commit 8164762
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion tiemao_2017/44_MongoDB_elemMatch/44_MongoDB_elemMatch.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ D:\mongo\mongodb-win32-x86_64-3.4.10\bin>mongod.exe -h


```
--dbpath arg directory for datafiles
--dbpath arg directory for datafiles
- defaults to \data\db\
which is D:\data\db\ based on the current working drive
```
Expand All @@ -223,6 +223,55 @@ mongod.exe --dbpath D:\data\db\
Studio 3T 支持 IntelliShell 控制台,在 Edit --> Preferences 中指定 `mongo.exe` 即可。


### 更新多条数据

[mongodb的update官方文档](https://docs.mongodb.com/manual/reference/method/db.collection.update/) 说明内容如下:

```
db.collection.update(
<query>,
<update>,
{
upsert: <boolean>,
multi: <boolean>,
writeConcern: <document>,
collation: <document>
}
)
```

可以看到, update 可以接受3个参数, 第一个是过滤条件, 第二个是执行的更新操作, 第三个是配置选项。


其中, 更新多条数据时,要指定选项 `{ multi:true }`


将第0个元素的content更新, 语句为:


```javascript
db.test.update
(
{
"_id": {
$in: [
"123",
"124"
]
}
},
{
"$set": {
"qList.0.content" : "医学伦理学的公正原则是"
}
},
{
multi:true
}
);
```




日期: 2017年10月23日
Expand Down

0 comments on commit 8164762

Please sign in to comment.