Mongo error: field names cannot start with $ [$set]
Mongo error: field names cannot start with $ [$set]
这可能是一个非常简单的错误,但我找不到它。 运行 这个简单的查询:
db.getCollection('thoughts').update(
{space: {type: 'list'}},
{space: {type: {$set: 'arrangement'}}}
);
我收到这个错误:
Error: field names cannot start with $ [$set] :
DBCollection.prototype._validateForStorage@src/mongo/shell/collection.js:185:1
DBCollection.prototype._validateForStorage@src/mongo/shell/collection.js:189:13
DBCollection.prototype._validateForStorage@src/mongo/shell/collection.js:189:13
DBCollection.prototype._validateUpdateDoc@src/mongo/shell/collection.js:416:9
Bulk/findOperations.updateOne@src/mongo/shell/bulk_api.js:675:9
DBCollection.prototype.update@src/mongo/shell/collection.js:483:13
@(shell):1:1
我使用 Mongo v3.2.6 和 Robomongo 1.0。
有什么想法吗?
试试这个:
db.thoughts.update(
{ "space.type": "list" },
{ $set: { "space.type": "arrangement" } }
);
请注意,要更新多个文档,您应该将 multi
选项设置为 true:
db.thoughts.update(
{ "space.type": "list" },
{ $set: { "space.type": "arrangement" } },
{ multi: true }
);
这可能是一个非常简单的错误,但我找不到它。 运行 这个简单的查询:
db.getCollection('thoughts').update(
{space: {type: 'list'}},
{space: {type: {$set: 'arrangement'}}}
);
我收到这个错误:
Error: field names cannot start with $ [$set] : DBCollection.prototype._validateForStorage@src/mongo/shell/collection.js:185:1 DBCollection.prototype._validateForStorage@src/mongo/shell/collection.js:189:13 DBCollection.prototype._validateForStorage@src/mongo/shell/collection.js:189:13 DBCollection.prototype._validateUpdateDoc@src/mongo/shell/collection.js:416:9 Bulk/findOperations.updateOne@src/mongo/shell/bulk_api.js:675:9 DBCollection.prototype.update@src/mongo/shell/collection.js:483:13 @(shell):1:1
我使用 Mongo v3.2.6 和 Robomongo 1.0。
有什么想法吗?
试试这个:
db.thoughts.update(
{ "space.type": "list" },
{ $set: { "space.type": "arrangement" } }
);
请注意,要更新多个文档,您应该将 multi
选项设置为 true:
db.thoughts.update(
{ "space.type": "list" },
{ $set: { "space.type": "arrangement" } },
{ multi: true }
);