Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

findOneAndUpdate() seems to not return result if no updates to apply #390

Closed
vkarpov15 opened this issue Apr 23, 2023 · 3 comments · Fixed by #392
Closed

findOneAndUpdate() seems to not return result if no updates to apply #390

vkarpov15 opened this issue Apr 23, 2023 · 3 comments · Fixed by #392
Assignees

Comments

@vkarpov15
Copy link
Collaborator

vkarpov15 commented Apr 23, 2023

Send the following commands to jsonapi and you'll see that findOneAndUpdate() returns no results, even though there's a document that matches.

{
  "deleteMany": {
    "filter": {}
  }
}

{
  "insertMany": {
    "documents": [
      {
        "username": "a"
      }
    ]
  }
}

{
  "findOneAndUpdate": {
    "filter": {},
    "update": {
      "$set": {
        "username": "a"
      }
    },
    "options": {
      "returnDocument": "before"
    },
    "sort": {
      "username": 1
    }
  }
}

Change the last command to the following and a document is returned.

{
  "findOneAndUpdate": {
    "filter": {},
    "update": {
      "$set": {
        "username": "aaa"
      }
    },
    "options": {
      "returnDocument": "before"
    },
    "sort": {
      "username": 1
    }
  }
}
@maheshrajamani
Copy link
Contributor

@vkarpov15 If there is no update to the document, the api currently doesn't return document. Will make the change to return document in this scenario too.

@maheshrajamani
Copy link
Contributor

@vkarpov15 I believe this behavior is required for findOneAndReplace() api too?

@vkarpov15
Copy link
Collaborator Author

@maheshrajamani yes, findOneAndReplace() as well. Although it looks like findOneAndReplace() isn't affected - the following series of commands seems to result in a document being returned from findOneAndReplace():

{
  "deleteMany": {
    "filter": {}
  }
}

{
  "insertMany": {
    "documents": [
      {
        "username": "a"
      }
    ]
  }
}

{
  "findOneAndReplace": {
    "filter": {},
    "replacement": {
      "$set": {
        "username": "a"
      }
    },
    "options": {
      "returnDocument": "before"
    },
    "sort": {
      "username": 1
    }
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants