I've been trying to move my data from reward.thisMonth
into reward.lastMonth
with this query
await this.userModel.updateMany(
{},
{
$set: {
'rewards.lastMonth': '$rewards.thisMonth',
'rewards.thisMonth': { usdt: 0, btc: 0, eth: 0 },
},
},
);
but I got this error :
CastError: Cast to Embedded failed for value "$rewards.thisMonth" at path "lastMonth"
I'm also trying to do with another approach like this
await this.userModel.updateMany(
{},
{
$set: {
'rewards.lastMonth': {
usdt: '$rewards.thisMonth.usdt',
btc: '$rewards.thisMonth.btc',
eth: '$rewards.thisMonth.eth',
},
'rewards.thisMonth': { usdt: 0, btc: 0, eth: 0 },
},
},
);
and I got this error
CastError: Cast to Number failed for value "$rewards.thisMonth.usdt" at path "usdt"
Both rewards.thisMonth
and rewards.lastMonth
have same schema structures.
How to fix this issue ?
I'm using mongodb v4.4.1