2023-02-22

Minimongo - How to cast a date typed as an object, to an actual date type

 db.COLLECTION.update(

    {

        $expr: {$eq: [{"$type": "$YOUR_DATE_FIELD"}, "object"]},

    },

    {$set: {

        "YOUR_DATE_FIELD": new Date(parseInt("$YOUR_DATE_FIELD.$date.$numberLong")),

    }},

    {

        multi: true, 

        upsert: false,

    }

);



Original issue: 

Uncaught MinimongoError: Key $date must not start with '$'