Created
April 24, 2012 17:47
-
-
Save kconragan/2481948 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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