node.js - UpdateMany Not a Function MongoDB + Node -
i writing piece of code run on npm-cron timer. here is:
var cronjob = require('cron').cronjob; var job = new cronjob({ crontime: '* * * * *', ontick: function() { var monk = require('monk'); // persistence module on mongodb var db = monk('localhost:27017/test'); console.log("hello cron job! " + new date()); var collection = db.get('activity'); collection.updatemany({"repetitions.today": {$gt: 0}}, { $set: { "repetitions.today": 0, } }, function(err, activity){ if (err) throw err; }); }, start: true, timezone: 'america/los_angeles' }); job.start(); the problem error on collection.updatemany() line. error states
updatemany not function
on other hand, if use update() instead of updatemany(), code works (but on first item in mongo collection, expected). doing wrong , causing this?
i tried re-writing using foreach() not recognized function.
hmm....
might want try (es6)
db.collection('activity').updatemany({"repetitions.today": {$gt: 0}}, { $set: { "repetitions.today": 0 } }).then(r => { console.log('success!'); }).catch(err => { console.log('error - ' + err); });
Comments
Post a Comment