Upsert in Meteor - selector troubles

时间:2015-05-12 23:36:44

标签: mongodb meteor

I have some code:

var deferred = $q.defer();

Now the issue is with the selector, specifically

Entrants.upsert({
    // selector
    race_id: entrant.race_id,
    eventbrite: {
        entrant_id: parseInt(entrant.eventbrite.entrant_id)
    }
}, {
    //modifier
    $set: entrant
},
function(error, result) {
    if (error) {
        var name = entrant.first_name + " " + entrant.last_name;
        console.log("Problem with " + name + ": " + error);
    }
    console.log("result: " + JSON.stringify(result));
}
)

I can't seem to search in child nodes, therefore the document is not found. If I change it to

eventbrite: {
    entrant_id: parseInt(entrant.eventbrite.entrant_id)
}

I get an error: "eventbrite.entrant_id": parseInt(entrant.eventbrite.entrant_id)

I'm doing something simple wrong, can anyone point it out?

EDIT: upserting with this selector MongoError: The dotted field 'eventbrite.entrant_id' in 'eventbrite.entrant_id' is not valid for storage. works if the document already exists - the document is upserted (updated). However if the document doesn't exist it errors "eventbrite.entrantId": parseInt(entrant.eventbrite.entrantId). It works fine if it's not a nested document. Bug in meteor?

0 个答案:

没有答案