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?
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.