What is the correct JSON schema to support a GeoJSON polygon?

Hi,

I am trying to create documents with a GeoJSON Polygon via Graphql but I cannot create the correct JSON schema to support this.

I have GeoJSON Points working as it is an array of numbers but the Polygon requires nested arrays and Mongo cannot generate the graphql schema even though my JSON schema is valid.

any help appreciated

1 Like

I have the same problem here, but with realmDB. When I add these nested arrays in my Realm Schema it throw the following message error:

array property “polygons” cannot be of type array to be sync-compatible

{
      "title": "Field",
      "properties": {
      
        "_appId": {
          "bsonType": "string"
        },
        "_id": {
          "bsonType": "objectId"
        },
        "active": {
          "bsonType": "bool"
        },
      
        "name": {
          "bsonType": "string"
        },

        "polygons": {
          "bsonType": "array",
          "items": {
            "bsonType": "array",
            "minItems": {
              "$numberInt": "2"
            },
            "maxItems": {
              "$numberInt": "2"
            },
            "items": {
              "type": "number"
            }
          }
        },
       

      "required": [
        "_appId"
      ]
    }

Hi Virmerson,

I have just got it working using the below JSON-schema and the real-web SDK I can create/upsert documents with a geojson polygon, however grapql is unable to generate the schema so I cannot use graphql until I figure out how to ignore a specific field validation.

Ultimately I want to find documents with geoIntersect between the user location polygon and the document location polygon so I will test this next :slight_smile:

"location": {
  "bsonType": "object",
  "properties": {
    "coordinates": {
      "type": "array",
      "items": {
              "type": "array",
              "items": {
                  "type": "array",
                  "items": {
                      "bsonType": "double"
                  }
              }
      }
    },
    "type": {
      "type": "string"
    }
  }
},
1 Like