Mongodb query MongoDB批量更新不起作用
我试图通过覆盖表中的所有电子邮件值(通过)来清理一组数据。以下内容不会导致错误,但也不会更新任何值:Mongodb query MongoDB批量更新不起作用,mongodb-query,Mongodb Query,我试图通过覆盖表中的所有电子邮件值(通过)来清理一组数据。以下内容不会导致错误,但也不会更新任何值: db.applicants.update( { institution_id: { $gt: 1 } }, {$set: {email: "sanitizedmail@there.com"}}, { multi: true }) 和样本记录: { "id": "0003ee8c-2288-11e4-9610-0015c5f288ee", "create
db.applicants.update(
{ institution_id: { $gt: 1 } },
{$set: {email: "sanitizedmail@there.com"}},
{ multi: true })
和样本记录:
{
"id": "0003ee8c-2288-11e4-9610-0015c5f288ee",
"created_at": "8/12/14 9:24",
"updated_at": "8/12/14 9:25",
"email": "some@there.com",
"institution_id": "379",
}
根据您的数据结构 机构识别码 字段类型为:text(2),因此$gt将无法执行操作 使用下面提供的代码段将其更改为整数:
db.applicants.find( { 'institution_id' : { $type : 2 } } ).forEach(
function (x) {
x.institution_id = parseInt(x.institution_id); // convert field to int
db.applicants.save(x);
})
你能给我们展示一下文档结构的例子吗?@profesor79谢谢。这里增加了一个例子:非常感谢。这就成功了。没有意识到该列被记录为文本。