I’m trying to run this code:
const query = { date: day.date, employee: employee };
const update = { $set: { date: day.date, employee: employee, date.marked: !date.marked }};
const options = { upsert: true };
DaysCollection.updateOne(query, update, options);
DaysCollection is normal MongoDB collection implemented as in the todolist manual. It says updateOne is not a function …is MongoDB for Meteor not including updateOne function - this means, the MongoDB Collection does not have updateOne function? …for similar errors in Google, answers say that the query is slightly wrong, but how can this affect, whether a function exists? Upsert option should do update or insert - is there another way to do update or insert in MongoDB for Meteor? With just “update” this is not possible, it says it works then only for _id field queries.
I’m trying to use this - https://www.mongodb.com/docs/drivers/node/current/fundamentals/crud/write-operations/upsert/ …when I use normal update instead, it says I have to use only id for this, it only works with updateOne.
Can I somehow, if this is not possible (to get to updateOne), do a transaction/atomic object to check, whether a record exists, and update it if it exists, insert otherwise? Or can I use another database object for this purpose, which supports updateOne? Meteor is still new to me and I don’t know it’s scopes very well - that DB query I could not put inside the function I was using, it wanted it directly inside the function of UI.
What I’m interested in - how to get to upsert function in MongoDB and Meteor.