Skip to content

Instantly share code, notes, and snippets.

@kconragan
Created April 24, 2012 17:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kconragan/2481948 to your computer and use it in GitHub Desktop.
Save kconragan/2481948 to your computer and use it in GitHub Desktop.
// controller
exports.createWave = function(req, res) {
// buoys come in from client sorted
var buoys = req.body.wave.buoys;
// how would I add an index to them
// and save below?
var wave = new Wave({
'name': req.body.wave.name,
'location': {
'lng': req.body.wave.location.lng,
'lat': req.body.wave.location.lat
},
'buoys': buoys
})
wave.save(function(err) {
if(err) {
throw err;
}
else {
Wave.findOne({ _id: wave.id }, function(err, wave) {
res.redirect('/waves/' + wave._id.toHexString())
});
}
});
};
// data model
var Wave = new Schema({
name: {
type: String,
required: true
},
location: {
lng: Number,
lat: Number
},
buoys: [{
type: Schema.ObjectId,
ref: 'Buoy'
}],
secret: Boolean
});
var Buoy= new Schema({
name: {
type: String,
required: true
},
mid: String,
cdipId: String,
location: {
lng: Number,
lat: Number
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment