How to create nested arrays in MongoDB Realm?

314 views Asked by At

I'm creating a webapp that uses geojson data. I want to store this data in MongoDB Atlas and access it through a MongoDB Realm. I followed the official MongoDB Documentation. The problem is that when I create a schema for my collection, the automatically generated GraphQL API doesn't recognize nested arrays. I'm relatively new to MongoDB, so I'm not sure if this is a problem related to MongoDB or GraphQL.

The schema for my collection (reduced for simplicity) is:

{
  "title": "test",
  "properties": {
    "_id": {
      "bsonType": "objectId"
    },
    "coords": {
      "bsonType": "array",
      "items": {
          "bsonType": "array",
          "minItems": 2,
          "maxItems": 2,
          "items": {
              "bsonType": "number"
          }
      }
    }
  }
}

It's just an array of arrays. Creating this schema gives no error. I can even validate the schema against documents and they pass. However, when I try to query them with GraphQL, I get the following warning:

Warning: JSON Schema could not be fully translated to a GraphQL schema. Some rules/fields were ignored.

error processing "type" property in JSON Schema

As a result, GraphQL ignores the "coords" property and I am unable to query it.

0

There are 0 answers