In Meteor, a MongoDB update is not seen in the Mongo shell -
this odd problem.
i running cursor.observe()
in tracker.autorun()
, changes occurring when refresh page. here imporant code:
client side
tracker.autorun(function (){ var initializing = true; links.find().observe({ added: function(doc){ var parents = links.find({stacks: {$exists: true, $not: {$size: 0}}}); //find parent of item stack array if(!initializing){ _.each(parents.fetch(), function(parentdoc){ _.each(parentdoc.stacks, function (stackid){ //the troublesome server call meteor.call("addlinksfromdirtostack", stackid, parentdoc.shared[0].id, parentdoc._id); }); }); } initializing = false; } }); });
server side
meteor.methods({ addlinksfromdirtostack: function(stackid, userid, dirid){ var stack = stacks.findone(stackid); if (stack){ var webarray = stack.webarray; webarrayfiller(dirid, webarray); stacks.update(stackid, {$set: {webarray: webarray}}); stacks.update(stackid, {$addtoset: {users: userid}}); } // note: if query stacks collection here, see changes } }); webarrayfiller = function(dirid, webarray){ //update array }
as commented above, if query stacks collection directly after update, changes reflected in database. however, querying mongo shell, still see old stack, without update. , case on client side, changes should displayed.
i have tried meteor reset no avail. appreciated.
i figured out why wasn't working.
i wasn't publishing every field of stacks
collection. in particular, not users
field. when attempt change collection line, fail:
stacks.update(stackid, {$addtoset: {users: userid}});
however, minimongo recognized change, , queries falsely show me had succeeded. once server rejected update, reject line directly above, making both changes not occur. apparently, find mongodb's lack of error messages in failed transactions troublesome. made error hard find.
the solution wrap server side code in if (meteor.isserver)
run on server side. unfortunate consequence values cannot returned these calls, due asynchronicity, there workarounds that.
Comments
Post a Comment