Questions tagged [findoneandupdate]

45 questions
0
votes
1 answer

MongoDB / Mongoose - FindOneById with conditions. Match value of Array within Object thats within an Array

I know the title of this question is quite a mouthful but I hope you understand what exactly I mean if I provide an example. This is my MongoDB structure: { "_id":{ "$oid":"62408e6bec1c0f7a413c093a" }, "visitors":[ { …
0
votes
2 answers

FindOneAndUpdate overriding and updating only the first id

I am simply trying to update the content according to the id, but whichever id I am using, it updates only the first id by overriding it. The flow goes as routes => controller => repository Following is the code: Routes…
Ritika
  • 131
  • 1
  • 12
0
votes
0 answers

mongoose findOneAndUpdate works but gives an error

I learn mongoose on NodeJS and I wanted to use usefindOneAndUpdate, it works on db I have the updates but the response gives an error and I couldn't find why help me pls. code: await userModel.findOneAndUpdate( { _id: req.params.id }, …
Kenyuki
  • 65
  • 1
  • 7
0
votes
2 answers

How to update an array value in mongodb using aggregation

My Document looks something like this { _id: ObjectId("60b114b2415731001943b17f"), processList:[ { processName: 'Wood cutting', createdAt: '2021-05-28T08:59:06.260Z', updatedAt: '2021-05-28T08:59:06.260Z', id:…
0
votes
1 answer

Mongoose FindOneAndUpdate: change value without overwriting current values

I have this schema { guildId: { type: String, required: true, unique: true }, systems:{ reactChat:{ type: Array, required: true, …
0
votes
4 answers

"error": "Cannot read property 'findOne' of undefined"

Hello everybody !! Here I have a big problem, I would like to do a registration in back with Node.js sequelize and mySql. I looked here and there but I did not find the answer to my problem so I came to ask you for help. With mongoDb, it was easier…
user15474257
0
votes
0 answers

MongoDB troubles with finding and modifying documents based on the same ID

I've been experimenting with nosql databases recently, mostly mongodb and I came to a weird blockage. To keep it really short I started implementing user auth / profile creation. User and profile have a 1-1 relationship. When a user is created, so…
someguy
  • 115
  • 5
0
votes
1 answer

Upgraded to Mongoose 5.12 and now I can't do findOneAndUpdate with $push operator

I just upgraded to Mongoose 5.12 from 5.11 and am using Typescript. I have this schema const MyFileSchema = new Schema({ objectID: { type: String, required: true }, attachments: { type: Array, required: false } }, { collection:…
Dave
  • 15,639
  • 133
  • 442
  • 830
0
votes
1 answer

findOneAndUpdate updates sometimes and sometimes doesnt

Ok so i have a schema as follows const newUserSchema = new mongoose.Schema({ name: { type: String, required: [true, "Check Data Entry, no name specified"] }, email: { type: String, required: [true, "Check Data Entry, no email…
0
votes
0 answers

Mongoose - Update multiple fields in nested array

I have below object. { _id: ObjectId(6082adfaeced28382c167bd7), inviteMountaineers: [{ _id: ObjectId(6082c4f9dcfaa86794601058), userId: ObjectId(60829eb5f1d2c316dfd79cd8), status:"Invited" },{ _id:…
Shelly
  • 410
  • 7
  • 26
0
votes
1 answer

How do I update with mongoose and check if email exists

Seems like I cannot figure it. The function must check if the email already exists in the collection. If the email exists then the person has already made an appointment. If the email exists, then an Update on the time must be executed. And if email…
0
votes
1 answer

How to do a document versioning in MongoDB using Driver

Requires document versioning in MongoDB while editing on the app. I have many "Cards" created by various users. A card can be edited at any point. The app must hold all the changes in the database so that an admin can roll back to old changes. To do…
PineCone
  • 2,193
  • 12
  • 37
  • 78
-1
votes
1 answer

I want to update payments document if found, create a new document with the updated field, leaving the original document

const payment = await paymentsSchema.findOne({ student: s_id, guardian: g_id }, {}, { sort: { 'createdAt': -1 } }) console.log(payment) payment.balance = (payment.balance + settings.overtime_rate) // Create…
zippy
  • 1
  • 1
-1
votes
1 answer

Mongoose findOneAndUpdate() executes multiple times

Bit of background, I have an express backend for my application that is using MongoDB as a database. Auth0 is there as an identity provider. I have an addTeamUser async function that: Validates the request body with Joi Takes an email from the…
Crashie
  • 19
  • 6
-1
votes
1 answer

Mongoose no longer accpet callback() MongooseError: Model.findOne() no longer accepts a callback

here is the error its says mongoose no longer accpet callback Model.findOne() no longer accept callback
1 2
3