cryptic mongodb error LEFT_SUBFIELD unterstützt nur Object: stats nicht: 6
Ich habe Probleme herauszufinden, was dieser Fehler bedeutet
LEFT_SUBFIELD unterstützt nur Object: stats, nicht: 6
Es scheint zu passieren, wenn ich in meine Profilsammlung einfüge. Ich benutze mongoose.js. Wir fügen die Anzahl der Posts in jeder Kategorie in die Eigenschaft stats ein, z.
<code>stats: {category:count, category2: count2}. </code>
Hier ist mein Schema
<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>
Ich denke, dass es passieren könnte, wenn ich das Statistikobjekt $ inc counts aktualisiere, so dass Statistiken zu so etwas wie diesem Update herauskommen können
<code>db.status.update({_id:xyz}, {$inc: { stats.foo : 1, stats.bar:1}}) </code>
Hier ist mein Mungo-Code
<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>