GBC*_*GBC 8 javascript updates mongoose mongodb node.js
我Article在MongoDB数据库的集合中有这个现有文档:
[ { site: 'www.atlantico.fr',
date: '2014-05-27T11:10:19.000Z',
link: 'http://www.atlantico.fr/example.html',
_id: 538473817eb00f082f4803fc,
__v: 0} ]
Run Code Online (Sandbox Code Playgroud)
我想在Node.js中使用Mongoose为这个文档添加一个day有价值的新字段'example'.所以我这样做:
Article.update(
{ link: 'http://www.atlantico.fr/example.html'},
{ $set : {day : 'example'} },
function(err){
});
Run Code Online (Sandbox Code Playgroud)
但是它不起作用,因为当我在那之后查询文档时,没有day出现新的字段......
在使用update或使用$setMongoose 时我一定犯了一个错误,但我找不到我的错误.
我错过了什么?谢谢!
小智 13
尝试
Article.update(
{link: 'http://www.atlantico.fr/example.html'},
{day : 'example' },
{multi:true},
function(err, numberAffected){
});
Run Code Online (Sandbox Code Playgroud)
并且不要忘记在架构中添加日期.
| 归档时间: |
|
| 查看次数: |
17262 次 |
| 最近记录: |