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

findOneAndReplace upsert not generating _id #416

Closed
kathirsvn opened this issue May 6, 2023 · 0 comments · Fixed by #421
Closed

findOneAndReplace upsert not generating _id #416

kathirsvn opened this issue May 6, 2023 · 0 comments · Fixed by #421
Assignees

Comments

@kathirsvn
Copy link
Contributor

kathirsvn commented May 6, 2023

When the findOneAndReplace API is called with upsert flag set to true, the new document is generated with the given properties in the replacement part of the request, but the _id is not generated. In the below example, you could see _id and upsertedId are not set in the final response.

To replicate the issue;

http: --- request POST http://localhost:8181/v1 
{
  "createNamespace": {
    "name": "testks1"
  }
}

http: --- request POST http://localhost:8181/v1/testks1 
{
  "createCollection": {
    "name": "products",
    "options": null
  }
}

http: --- request POST http://localhost:8181/v1/testks1/products {
  "findOneAndReplace": {
    "filter": {
      "name": "Product 25"
    },
    "replacement": {
      "name": "Product 25",
      "isCertified": false,
      "price": 20
    },
    "options": {
      "upsert": true,
      "returnDocument": "after"
    }
  }
}


http: --- response 200 POST http://localhost:8181/v1/testks1/products 
{
  "data": {
    "document": {
      "_id": null,
      "name": "Product 25",
      "isCertified": false,
      "price": 20
    }
  },
  "status": {
    "matchedCount": 0,
    "modifiedCount": 0,
    "upsertedId": null
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants