I try to create a schema without predefined names. I found the “dictionary” option on documentation.
but my schema dont work:
“paymentObject”: {
“additionalProperties”: {
“bsonType”: “string”
},
“bsonType”: “object”
},
and show the message
What am I doing wrong?
Hi @Edir_Dumaszak ,
The top-level schema should follow the format defined here: https://www.mongodb.com/docs/atlas/app-services/schemas/#define-a-schema . To make your schema valid, the object you shared should be an entry in a top-level properties
key.
Hi @Kiro_Morkos
I need populate the field `paymentObjetct with a graphql mutation, but is seem impossible.
This field no has fixed fields.
I tries several ways without success.
Can you help me?
below my schema:
{
"tile": "payment",
"additionalProperties": true,
"properties": {
"_id": {
"bsonType": "objectId"
},
"createdAt": {
"bsonType": "date"
},
"createdBy": {
"bsonType": "string"
},
"organization": {
"bsonType": "objectId"
},
"paymentStatus": {
"bsonType": "string"
},
"paymentUpdateAt": {
"bsonType": "date"
},
"status": {
"bsonType": "string"
},
"totalAmount": {
"bsonType": "number"
},
"type": {
"bsonType": "string"
},
"paymentObject": {
"bsonType": "object",
"additionalProperties": {
"bsonType": "string"
}
}
}
}
Anuj_Garg
(Anuj Garg)
June 22, 2023, 10:42am
4
You wouldn’t be able to have a dictionary-like object here. But if an array of each item as key-value pair works for you. You can do that by
"paymentObject": {
"bsonType": "array",
"items": {
"bsonType": "object",
"properties": {
"key": {
"bsonType": "string"
},
"value": {
"bsonType": "string"
}
}
}
}
1 Like
Thank you @Anuj_Garg
This solve my problem.
But I still no know why the dictionary no works. Can you explaim to me?
Anuj_Garg
(Anuj Garg)
June 22, 2023, 6:10pm
6
Dictionary doesn’t fit in schema structure available.
If you field type to Object, you will be expected to set keys and their value types within schema definition. Otherwise schema would not compile.
1 Like
system
(system)
Closed
June 27, 2023, 6:11pm
7
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.