mongodb push-array

Habe ich das folgende schema. Ich bin mit node.js mit mongodb

attributes: {
    type: { type: 'string' },
    title: { type:'string' },
    description: { type:'string' },
    is_active: { type:'boolean',defaultsTo:true },
    createdBy: { type:'json' },
    attachments:{ type:'array' }
}

arr = [{
    'id':attResult.id,
    'subtype':type,
    'title'  : attResult.title,
    'body'  : attResult.body,
    'filetype' : attResult.filetype
}];

Ich bin versucht, eine Anlage in das "Anlagen" - array, das einzigartig sein wird, um das Dokument.

Dies ist meine Abfrage.

books.update(
    { id: refid },
    { $push: { attachments: arr } }
).done(function (err, updElem) {
    console.log("updElem" + JSON.stringify(updElem));     
});

Was ist das problem in meiner Abfrage,kein Fehler aber nicht aktualisiert Anhänge.

Möchte ich mein Ergebnis ist dies:

{ 
    "_id" : 5,
    "attachments": [
        { 
            "id": "xxxxxxx",
            "subtype": "book",
            "title": "xxxx",
            "body": "xxxx" ,
            "filetype" : "xxxxx"
        },
        {
            "id": "xxxxxxx",
            "subtype": "book",
            "title": "xxxx",
            "body": "xxxx",
            "filetype": "xxxxx"
        }
    ]
}
  • Was sind Sie wirklich hier? Mungo vielleicht? Meinst du "Attribute", um Ihre schema-definition? Oder ist die definition tatsächlich zusätzliche Felder in ein Feld namens "Attribute"?
InformationsquelleAutor user3046205 | 2014-06-07
Schreibe einen Kommentar