我无法弄清楚这个错误意味着什么
LEFT_SUBFIELD仅支持Object:stats not:6
当我插入我的个人资料集合时,似乎正在发生这种情况.我正在使用mongoose.js.我们在stats属性中插入每个类别的帖子数,例如
stats: {category:count, category2: count2}.
Run Code Online (Sandbox Code Playgroud)
这是我的架构
var ProfileSchema = new Schema({
uname: {
type: String,
required: true,
index: true,
unique: true
},
fname: String,
lname: String,
stats: {
type:{},
"default":{},
required:true
},
created: {
type:Date,
required:true,
"default":Date.now
}
});
Run Code Online (Sandbox Code Playgroud)
我认为当我更新stats对象$ inc count时可能会发生这种情况,这样统计数据可能会出现类似这样的更新
db.status.update({_id:xyz}, {$inc: { stats.foo : 1, stats.bar:1}})
Run Code Online (Sandbox Code Playgroud)
这是我的猫鼬代码
var tags = ["comedy", "action", "drama"];
//also adding the postId to the posts collection of profile
var updateCommand = {$push: {posts: post._id}};
var stats = {};
for (var i = tags.length - 1; i >= 0; i--){
stats["stats." + tags[i].toString()] = 1;
};
updateCommand.$inc = stats;
Profile.update(
{uname: uname},
updateCommand,
{safe:true, upsert:true},
callback
);
Run Code Online (Sandbox Code Playgroud)
ale*_*lex 24
如果您尝试更新非对象的子文档,也会发生这种情况.
> db.test.insert({_id: 10240292, object: 'some string'})
> db.test.update({_id: 10240292}, {$set: {'object.subkey': 'some string'}})
LEFT_SUBFIELD only supports Object: object not: 2
Run Code Online (Sandbox Code Playgroud)
也许这不是你的情况,但它可以帮助那些谷歌搜索这个错误的人.
你可能会遇到这样的情况:
https://jira.mongodb.org/browse/SERVER-2651
或者
https://jira.mongodb.org/browse/SERVER-5227
这两个问题都已在 2.1 开发分支中修复,但尚未向后移植到 2.0
这里有一个关于类似问题的不错的讨论:
https://groups.google.com/forum/?fromgroups#!topic/mongodb-user/VhjhcyEdbNQ
基本上,这可以归结为这样一个事实:您可能在更新过程中传递了一个空密钥,这是需要避免的。
| 归档时间: |
|
| 查看次数: |
2763 次 |
| 最近记录: |