How do I solve: 'MongoError: $where is not allowed in this atlas tier' when using MongoDB Atlas?
Here is my code:
async function getEventsTakingPlace(){
const getEventsTakingPlace = await event.find({$where: function() {
return ((this.eventTime < new Date()) && (new Date(this.eventTime).getTime()+ 100*60000 > new Date().getTime() ) ) }},
function(err, events){
if(err){
return err;
}else {
return events;
}
});
return getEventsTakingPlace
};
when I use my local mongoDB instance it works but once i start ising mongoAtlas I get the error: $where is not allowed in this atlas tier. How do I solve this?
I have just been told that the free tier (M0), M2 and M5 Instances have some limitations and command limitations, including limited metrics for analysis. I therefore have to upgrade to get more features....
While $where
may not be supported by the Atlas tier you're using, the good news is that you don't need to use it for this query.
Instead, use a query like:
let now = new Date();
let min = new Date();
min.setTime(now.getTime() - 100*60000);
const events = await event.find({eventTime: {$gt: min, $lt: now}});
In general, you only want to use $where
as a last resort anyway, as it's not efficient.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With