cron - How to use rawCollection for aggregate in meteor? -


i need use bulk operations aggregate in order delete duplicates condition in database. tried use rawcollection() don't know how.

here's code need execute cron every x hours

function removedups() {   var count = 0,     collection = beatmaps.rawcollection(),     bulk = collection.initializeunorderedbulkop();   collection.aggregate([     { '$sort': { 'difficultyrating': -1 }},     { '$group': { '_id': '$beatmapset_id', 'ids': { '$push': '$_id' }, 'count': { '$sum': 1 }}},     { '$match': { 'count': { '$gt': 1 }}}   ]).foreach(function(doc) {     doc.ids.shift();     bulk.find({'_id': { '$in': doc.ids }}).remove();     count++;     if(count === 100) {         bulk.execute();         bulk = collection.initializeunorderedbulkop();     }   });    if(count !== 0) {     bulk.execute();   } } 

but produces error: cannot call method 'foreach' of undefined

so should do?

okay, after bit of research found similar question , here's did make work:

var aggregate = meteor.wrapasync(collection.aggregate, collection); 

and then

aggregate(parameters).foreach(...); 

Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -