MongoEncodingError with Array

I have a collection which has an array defined in the schema (Realm App). It is NOT a required field…

“imageServiceIds”: {
“bsonType”: “array”,
“items”: {
“bsonType”: “string”

Some of my documents have imageServiceIds defined with an array of strings, some do not have it defined at all. In the realm logs, I am getting the following error for those documents that do not have the array defined.

Failed to convert MongoDB document with configured schema during initial sync…Detailed Error: field update at path { table: "Item", fullPath: "imageServiceIds" } should have been an array value but was object

I should also note the collection name is “items” but the schema has a title of “Item” (not sure if its an issue or not).

How should I handle this scenario? I know I can ensure the underlying document has the field defined with an empty array but this won’t help me in the future when I want to add another array field and all the existing documents do not have it defined.


Assuming you’ve verified you created your validator correctly by taking a look at it in Compass, you are most likely are upserting something but not upserting an actual array. MongoDB tends to tell the truth, albeit in somewhat unhelpful terms.

Thank you very much. Compas was showing a value of undefined for the property (and error on my part in the way I imported the data). Not sure why the web ui didn’t display that undefined data but at least I found it and will now use Compas going forward.

1 Like

Good work @Robert_Charest