我已经看到,每当我们将任何值更新到 mongo 集合中时。更新后,它会按字母顺序重新排列键。假设当前模式是
_id:"Objectid(blah blah)"
id: "1",
fullname: "user",
username: "username",
password: "password",
更新后变成
_id:"Objectid(blah blah)"
fullname:"user"
id:"1"
password:"password"
username:"user"
我知道这没有问题。这不会影响任何事情,因为数组数据仍然与值相对应。但我只是想知道为什么会这样。
编辑:
这是mongoshell中的更新函数代码。但这并没有帮助我
function (query, obj, upsert, multi) {
assert(query, "need a query");
assert(obj, "need an object");
var firstKey = null;
for (var k in obj) {
firstKey = k;
break;
}
if (firstKey != null && firstKey[0] == "$") {
this._validateObject(obj);
} else {
this._validateForStorage(obj);
}
if (typeof upsert === "object") {
assert(multi === undefined, "Fourth argument must be empty when specifying upsert and multi with an object.");
opts = upsert;
multi = opts.multi;
upsert = opts.upsert;
}
this._db._initExtraInfo();
this._mongo.update(this._fullName, query, obj, upsert ? true : false, multi ? true : false);
this._db._getExtraInfo("Updated");
}