Hello, I’m facing a problem with my query. I was trying to update some documents on MongoDB realm. I have a field ‘startDate’ and what I want is to add 5 more days with the startDate of the document. But its not working. I tried this:
const reAdjustTargetDateOnDrop = async (
targetStartDate: Date,
track: string,
studentId: string
) => {
const result = await PICollection.updateMany(
{
trackNo: track,
startDate: { $gte: targetStartDate },
studentId: new Realm.BSON.ObjectID(studentId),
},
[
{
$set: {
startDate: {
$dateAdd: {
startDate: "$startDate",
unit: "day",
amount: 5,
},
},
},
},
]
);
return result;
};
I’m getting this error: “cannot transform type primitive.D to a BSON Document: WriteArray can only write a Array while positioned on a Element or Value but is positioned on a TopLevel”
but when I try this :startDate: new Date(“2023-05-21”), this is working