Last active
September 1, 2018 16:53
-
-
Save spolat/2f646480ebd33980f39457a826d12a7e to your computer and use it in GitHub Desktop.
This file contains 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
// Books Schema | |
var bookSchema = new Schema({ | |
name: String, | |
postedBy: {type: mongoose.Schema.Types.ObjectId, ref: 'User'}, | |
dateCreated: Date, | |
}); | |
// Registering Schema | |
var Book = mongoose.model('Books', bookSchema); | |
// User Schema | |
var userSchema = new Schema({ | |
fullName: String, | |
age: Number, | |
books: {type: mongoose.Schema.Types.ObjectId, ref: 'Books' | |
}); | |
// Registering Schema | |
var User = mongoose.model('User', userSchema); | |
Book.findOne({_id: 123}) | |
.populate('users') | |
.exec(function(err, post) { | |
// code here | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment