Clean up unsupported options before calling JSON API
kathirsvn opened this issue · comments
Kathiresan Selvaraj commented
There are options
sent by mongoose
(and not explicitly by the end user), which are not supported by the JSON API. This PR cleans them up by checking if every option in the options
, is supported by the JSON API or not.
For example, when we try findOneAndReplace
(from mongoose client model instance), we get below error (where overwrite
is not a field end user set in this case).
error: Error: Command "findOneAndReplace" failed with the following errors:
[{"message":"Unrecognized field \"overwrite\" (class io.stargate.sgv2.jsonapi.api.model.command.impl.FindOneAndReplaceCommand$Options), not marked as ignorable (2 known properties: \"returnDocument\", \"upsert\"])\n at [Source: (ByteArrayInputStream); line: 1, column: 202]
(through reference chain: io.stargate.sgv2.jsonapi.api.model.command.impl.FindOneAndReplaceCommand[\"options\"]->io.stargate.sgv2.jsonapi.api.model.command.impl.FindOneAndReplaceCommand$Options[\"overwrite\"])","exceptionClass":"UnrecognizedPropertyException"}]
Request
await Cart.findOneAndReplace({ cartName: 'wewson' },
{ name: 'My Cart 2', cartName: 'wewson1' },
{ returnDocument: 'after'}
).exec();
"findOneAndReplace": {
"filter": {
"cartName": "wewson"
},
"replacement": {
"cartName": "wewson1",
"name": "My Cart 2"
},
"options": {
"returnDocument": "after",
"overwrite": true,
"returnOriginal": false,
"projection": {}
}
}
We could see options like overwrite
, returnOriginal
, projection
in the request which are not supported/allowed by JSON API