Hello ,
I am new in MongoDB Atlas realm, this is why I am asking for help on the following context:
I have a Mongo shell script that is removing data by bulk, I have tested it manually and it works
SO, I need to schedule this task to be executed one time per week,
I wanted to know if it is possible to adapt the shell script to be run using realm feature (creating a function and scheduling it through a trigger)
Do you have any example to help me to implement this kind of task?
Thank you for your help
And best regards
Sandrine
here is a piece of the script:
let counter = 0;
let q = db[collection_name].find({"theField": myvalue}); // Perform a find
let total = q.count();
if(total > 0){
let bulk = db[collection_name].initializeUnorderedBulkOp();
// iterate over the collection
q.forEach(function(d) {
counter++;
bulk.find({ _id: d._id }).remove();
if (counter % 500 == 0) { // Execute when we have 500 documents in our bulk operation
result = bulk.execute();
sleep(1000); // Sleep for time
bulk = db[collection_name].initializeUnorderedBulkOp(); // Initialize on collection for next iteration
}
});
//last block
if(counter > 0){
bulk.execute();
}