How do I make MongoDB itself or some node.js driver for MongoDB require my documents to be a subset of a certain predefined schema. I've heard it's possible, but I'm so far not finding exactly how to do it.
I know that mongoose.js allows you to define a schema. For example:
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var blogSchema = new Schema({
title: String,
author: String,
body: String,
comments: [{ body: String, date: Date }],
date: { type: Date, default: Date.now },
hidden: Boolean,
meta: {
votes: Number,
favs: Number
}
});
With that you can define the schema of your collection.