Hello,
I’m having an issue using atlas app services data api. I am attempting to insert one document as per the call below:
curl --location 'https://eastus2.azure.data.mongodb-api.com/app/APP_ID/endpoint/data/v1/action/insertOne' \
--header 'apiKey: API_KEY' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--data '{
"dataSource": "mongodb-atlas",
"database": "DATABASE_NAME",
"collection": "COLLECTION_NAME",
"document": {
"name": "Test",
"assetId": 1234
}
}'
My app services schema for property
is defined as:
{
"title": "property",
"properties": {
"_id": {
"bsonType": "objectId"
},
"name": {
"bsonType": "string"
},
"assetId": {
"bsonType": "int"
}
},
"required": [
"_id",
"name",
"assetId"
]
}
The call fails with the following error (from the app services logs):
ERROR: could not validate document '' for insert
{
"name": "data/v1/insertOne"
}
However, if I provide an _id
objectId in the payload, the insert succeeds - I was under the impression that I would never have to provide that id, that it would be generated by the insert.
I appreciate any help with this.