I am using Mongoose 2.7.0 with node.js.
How can I describe a schema with a single embedded object?
Effectively I want to end up my schema matching with a JSON structure like:
{
title: "",
position: {
loc: [0, 0],
street: "",
zip: 1234,
town: "Name"
}
}
So far I've ended up with a solution like:
var MySchema = new mongoose.Schema({
title: { type: String },
position: {}
});
The problem in this solution is that it doesn't validate contents of position
.
The simplest way is to do something like this:
var MySchema = new mongoose.Schema({
title: { type: String },
position: {
loc: [Number],
street: String,
zip: Number,
town: String
}
});