I am trying to determine if a document exists in a collection. If the document exists, I wish to add a property "unread = false" to an object. 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:
functionxyz = (db, uid, events, done) ->
async.each events, (eventobj) ->
if db.Event.find(eventobj).count() > 0
eventobj.unread = false
else
db.Event.insert eventobj
eventobj.unread = true
done null, events
The error I am receiving is
/Users/owner/Desktop/coding challenge/repo/node_modules/mongodb/lib/mongodb/connection/base.js:246
throw message;
^
TypeError: callback is not a function
at /Users/owner/Desktop/coding challenge/repo/node_modules/mongodb/lib/mongodb/collection/commands.js:55:5
at /Users/owner/Desktop/coding challenge/repo/node_modules/mongodb/lib/mongodb/db.js:1197:7
at /Users/owner/Desktop/coding challenge/repo/node_modules/mongodb/lib/mongodb/db.js:1905:9
at Server.Base._callHandler (/Users/owner/Desktop/coding challenge/repo/node_modules/mongodb/lib/mongodb/connection/base.js:453:41)
at /Users/owner/Desktop/coding challenge/repo/node_modules/mongodb/lib/mongodb/connection/server.js:488:18
at [object Object].MongoReply.parseBody (/Users/owner/Desktop/coding challenge/repo/node_modules/mongodb/lib/mongodb/responses/mongo_reply.js:68:5)
at [object Object].<anonymous> (/Users/owner/Desktop/coding challenge/repo/node_modules/mongodb/lib/mongodb/connection/server.js:446:20)
at emitOne (events.js:77:13)
at [object Object].emit (events.js:169:7)
at [object Object].<anonymous> (/Users/owner/Deskto
Can someone explain to me the reason this error is occurring and what a potential solution might be?