Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

UPDATE doesn't work in mongoose #2221

Copy link
Copy link
Closed
@thomsa

Description

@thomsa
Issue body actions

Hi!

I've encountered an error while trying to update entities.

This is the generated code:
findOneAndUpdate(req.params.id, req.body, {upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()
It was always updating the first element in the collection, because it's not specified what field it should compare.
As in the mongoose documentation:
query.findOneAndUpdate(conditions, update, options)
The condition is not really a condition in the generated code.

I had to change it to the code below and it started to work as expected
entity.findOneAndUpdate({"_id" : req.params.id }, req.body, {upsert: true, setDefaultsOnInsert: true, runValidators: true}).exec()

Has anybody encountered this problem, or is it written in some documentation that this is what we have to do if we want it to work? I haven't found it in any docs though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.