Tools to enforce a schema?

Hi. I know that Couchbase is NoSQL, and NoSQL is schema-on-read, not schema-on-write. I know this has many advantages. But suppose I want to enforce a particular JSON schema on all docs I write to a certain bucket, or docs with a certain “type” field?

What is the standard way to do this in Couchbase? Just have the application code use something like ( before writing a doc to Couchbase? Any more transparent, built-in tools?


Hi @chuck.connell,

Good point. We will consider this for future improvement.

thanks! so nothing magic or easy right now?

Hi @chuck.connell,

I created the schema inferencing feature that is new in version 4.5, which is accessed through the N1QL ‘infer’ statement, and the “Bucket Analysis” section of the query workbench. While many users really love the schema flexibility that Couchbase provides, I could see that we really needed to provide tools to help users see what document structures exist in a bucket.

The infer statement could help you out, but only in retrospect to validate that documents in a bucket have the same schema.

Your application-based approach sounds like the best way to prevent improperly-formed JSON from getting in to the bucket in the first place. As Gerald notes, we will consider this as a future improvement.


thank you. i will check out the infer feature.