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.
<code>stats: {category:count, category2: count2}. </code>
Oto mój schemat
<code>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 } }); </code>
Myślę, że może się to zdarzyć, gdy aktualizuję obiekt statystyk $ inc, aby statystyki mogły wyjść na coś takiego jak ta aktualizacja
<code>db.status.update({_id:xyz}, {$inc: { stats.foo : 1, stats.bar:1}}) </code>
Oto mój kod mangusty
<code> 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 ); </code>