I am trying to determine if a document (received as part of an array of objects) exists in a collection. If it does not exist, I wish to insert the document and add "unread = true" to the object.
Code in coffee script for the above is as follows:
updateEvents = (db, events, done) ->
async.each events, (eventobj, cb) ->
# check whether event exists in event collection
db.Event.count eventobj, (err, count) ->
# if it doesn't
if count is 0
# insert the document and when finished set an unread property on this object to true
db.Event.insert eventobj, (err) ->
eventobj.unread = true
# if it does, log that is was found
else
console.log "yep, found it"
# pass results back up chain to client
done null, events
The unread property appears on the eventobj when console logged after assignment, however, it does not persist when passed to the client. It is as if the assignment never happened. Why is this occurring?
This is different than the type error question as it involves a data flow issue and not an error of any kind.