Chcete-li nastavit UsersAndQuestions:
, musíte přidat objekt{$addToSet: {UsersAndQuestions: { userID: idToAdd, questionID: questionToAdd } }}
AKTUALIZACE.
Udělal bych to dvěma dotazy:
Listing.update({_id: ObjectId(listingToUpdate), 'UsersAndQuestions.userID': idToAdd},
{"$addToSet": {"UsersAndQuestions.$.questionID": questionToAdd}}
, function (err, result) {
if(result.n === 0){
//we haven't found document with the userId - idToAdd
//we need to insert to UsersAndQuestions document with this user
Listing.update({_id: ObjectId(listingToUpdate)},
{$addToSet: {UsersAndQuestions: { userID: idToAdd, questionID: questionToAdd } }},
function(err, res){
})
}
})