How to specify in Pymongo validator key type in object?

40 views Asked by At

I want to define a schema in pymongo for documents where one element is a list of key-values pairs. Specifically, the key is a long type and each value is a fixed size array of 3 floats. For example a document might look:

{
"name": "doc1",
"measurements": [
  {168810123120: [1.2, 3.3, 4.4]},
  {168810123220: [2.2, 4.3, 5.4]},
  ]
}

I was trying with a validator that looks like

validator = {
    "$jsonSchema": {
        "bsonType": "object",
        "required": ["name", "measurements"],
        "properties": {
            "name": {
                "bsonType": "string",
                "description": "must be a string and is required"
            },
            "measurements": {
                "bsonType": "array",
                "description": "must be an array and is required",
                "items": {
                    "bsonType": "object",
                    "description": "Some description"
                },
                "minItems": 1,
            },

        }
    }
}

But it is not specifying the the object should have a key of type long and the value should be an array of a given length: can that be specified?

0

There are 0 answers