Automattic / mongoose

MongoDB object modeling designed to work in an asynchronous environment.
https://mongoosejs.com
MIT License
26.92k stars 3.84k forks source link

findOneAndUpdate does not work #6808

Closed PavelYarysh closed 6 years ago

PavelYarysh commented 6 years ago

Hello, I recently faced the following problem: I am trying to perform findOneAndUpdate() function.

I am calling it in the following line: const data = await db.Quote.model.findOneAndUpdate(query,updateObj,options) .catch(err => logError('Error while querying db for search', err)); where: let query = { 'make__dw':"asdf" }; const updateObj = { '$set':{ 'model__dw':'zamay' } }; and let options = { 'upsert':true };

So this code does not update the document. The problem can be that I moved to the kubernetes cluster deployment and created authentication, however modifying data works in Mongo Compass and the find() function works good as well. Before I used same syntax for single database without auth and it worked perfectly. I also tried to perform the update() function: const update = await db.Quote.model.update(query,updateObj,options) .catch(err => logError('Error while querying db for search', err)); and got the following output: { ok: 0, n: 0, nModified: 0 }

mongoose version: 4.5.8 mongodb version 4.0.0

vkarpov15 commented 6 years ago

What does your schema look like? Also, are you sure there's a document that matches { make__dw: 'asdf' }?

PavelYarysh commented 6 years ago

@vkarpov15 Hello, sorry for such late response, I figured that out, yes, its was problem with schema. By the way I am wondering why there is no option for not specifying replicaSet when connecting to multiple IP addresses like it was in 4.5.8 version? I am exposing kubernetes cluster and when I specify the replicaSet cluster changes the host addresses and everything is being screwed