tajemniczy błąd mongodb LEFT_SUBFIELD obsługuje tylko obiekt: statystyki nie: 6
Mam problem z ustaleniem, co oznacza ten błąd
LEFT_SUBFIELD obsługuje tylko obiekt: statystyki nie: 6
Wydaje się, że dzieje się tak, gdy wstawiam do mojej kolekcji profili. Używam mongoose.js. W właściwości stats wstawiamy liczbę postów w każdej kategorii, np.
stats: {category:count, category2: count2}.
Oto mój schemat
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
}
});
Myślę, że może się to zdarzyć, gdy aktualizuję obiekt statystyk $ inc, aby statystyki mogły wyjść na coś takiego jak ta aktualizacja
db.status.update({_id:xyz}, {$inc: { stats.foo : 1, stats.bar:1}})
Oto mój kod mangusty
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
);