My stored doc in mongo is :
[{
_id: 'Bd5r6vmb6bu5R2chQ',
run_status: true,
start_time: 2024-06-23T20:19:12.000Z,
stop_time: 2024-06-23T20:19:12.000Z,
strategies: [],
summary: '{"pnl_per":0,"pnl":0,"profit":0,"loss":0,"win":0,"lose":0,"win_per":0,"ppt":0}',
result: {}
}]
I am using meteor to develop the application with the built in mongo libs.
Now when I am trying to update the existing doc with some new attribute - “flag”: true. But ending up getting error :
(node:81184) UnhandledPromiseRejectionWarning: MongoServerError: The positional operator did not find the match needed from the query.
Here is my code to update the doc :
let doc = LiveStrategies.find({}, {sort: {start_time: -1, limit: 1}}).fetch()[0];
LiveStrategies.update( { _id: doc._id }, { $set: { flag: true } },
(updateErr) => {
if (updateErr) {
console.error('Error updating document:', updateErr);
return;
}
console.log('Document updated successfully.');
}
}
);
When i test with find query, its working perfectly fine and getting the doc correctly.
Appreciate your help on resolving this.