I’m trying to use the REST API to update a field in a record in MongoDB. The field is of type ObjectId, but the API refuses to accept the Extended JSON syntax for an ObjectId.
I’m using a PATCH request with the following body:
{
"testVal": { "$oid": "5a31edc2743bb8f105db877d" }
}
The response I get is:
{
"error": {
"code": 500,
"message": "The dollar ($) prefixed field '$oid' in 'testVal.$oid' is not valid for storage."
}
}
I have tested the Extended JSON syntax for a Date (i.e. the “$date” syntax) and that works fine, so it seems to be a problem with ObjectIds specifically. I have also tried the mongo shell syntax of ObjectId(“5a31edc2743bb8f105db877d”), but that doesn’t work either.
Can anyone tell me how to update an ObjectId field?