Created
August 3, 2016 08:11
-
-
Save drhanlau/7d0866797412b6d7c13c1dd5c321ef80 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
var mongoose = require('mongoose'), Schema = mongoose.Schema | |
mongoose.connect('mongodb://localhost/tour'); | |
var tourActivitySchema = Schema({ | |
title : String | |
}); | |
var tourPackageSchema = Schema({ | |
_id : Number, | |
name : String, | |
activities : [tourActivitySchema] | |
}); | |
var TourPackage = mongoose.model('tourpackage', tourPackageSchema); | |
var TourActivity = mongoose.model('touractivity', tourActivitySchema); | |
var a1 = new TourActivity(); | |
a1.title = "Skydiving"; | |
var t1 = new TourPackage(); | |
t1._id = 1; | |
t1.name = "5D4N Melbourne Tour" | |
t1.activities = [a1]; | |
// t1.save(function(err) { | |
// if (err) throw err; | |
// console.log('Tour saved!'); | |
// }); | |
var results = TourPackage.find({"_id":1},function(err,data) | |
{ | |
console.log(data); | |
console.log(data[0].activities); | |
} | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment