Azure Cosmos DB (Mongo API) Error: ‘validator’ is not supported

I ran into an issue with the MongoDB API on Azure Cosmos DB the other day. I could not find any information about it using web search, so I thought I would put up a page about it here.

Here is a sample of what I was trying to do, along with the error response:

globaldb:PRIMARY> db.createCollection( "contacts",
... { validator: { $or:
... [
... { phone: { $type: "string" } },
... { email: { $regex: /@mongodb\.com$/ } },
... { status: { $in: [ "Unknown", "Incomplete" ] } }
... ]
... }
... } )
{
"_t" : "OKMongoResponse",
"ok" : 0,
"code" : 115,
"errmsg" : "'validator' is not supported",
"$err" : "'validator' is not supported"
}

The reason?

Azure Cosmos DB’s MongoDB API does not support document validation.

Yet.

They are supposed to support it in the future, and I am uncertain as to when that will be.

I hope this helps someone. At least you’ll know, if you’re getting this error, that you are not alone.