Codrin Sirboiu
Codrin Sirboiu

Reputation: 33

MongoDB - Cannot create json schema with INTEGER

I am trying to create a collection with a json schema for validation. I got stuck on the following error and couldn't find anything related to it. I managed to create the schema using number type, but integer seems to throw this error.

Using mongodb-driver-sync and mongodb-driver-legacy v4.2.3

Caused by: com.mongodb.MongoCommandException: Command failed with error 9 (FailedToParse): '$jsonSchema type 'integer' is not currently supported.' on server 127.0.0.1:27017. The full response is {"ok": 0.0, "errmsg": "$jsonSchema type 'integer' is not currently supported.", "code": 9, "codeName": "FailedToParse"}

Tried changing the json schema from Compass and I'm getting the same error, so the problem is definitely coming from the database, not the driver. enter image description here

Upvotes: 2

Views: 572

Answers (1)

RickN
RickN

Reputation: 13500

MongoDB's JSONSchema doesn't, per the documentation, support Integer.

Omissions

The following are not supported in MongoDB's implementation of JSON Schema:

  • The integer type. You must use the BSON type int or long with the bsonType keyword.
createTime: {
    bsonType: "int"
}

Upvotes: 1

Related Questions