How to updateMultiple documents in mongoose base on current value of document
I have the following mongodb model:
const schema = new Schema({
timezone: {
type: String,
},
datetimeBaseOnTimezone: {
type: String,
}
})
I want to update the datetimeBaseOnTimezone with the current Date for each document in database base on current timezone of each document this using a single query.
Something like this:
await Model.updateMany({},(element) => ({
datetimeBaseOnTimezone: new Date(new Date().toLocaleString('en-US', { timeZone: element.timezone }))
}));
there is any solution similar to this approach?
from Recent Questions - Stack Overflow https://ift.tt/39IxT2A
https://ift.tt/eA8V8J
Comments
Post a Comment