Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .get(function(req,res){
- //returning aggregate values from comments part.. comment.authorId must hv user.username.
- CardComment.aggregate([ //stackoverflow qn... ask tomorrow show the models
- //now perform the mongo join of multiple collections like in SQL Joins
- {
- $lookup:{
- from: 'users', //external collection.
- localField: 'authorId', //input field., from current collection.. cardComments
- foreignField: '_id', //foreign key from external collection,
- as: 'commentUser'
- }
- },
- //filter according to the cardId.. part. find()... first pipeline
- {
- $match:{"card": req.params.cardId }
- }
- ], function(err,comments){
- if (err) {
- res.json({"success":false, "message": 'Error in loading comments'})
- } else {
- //res.json({"success": true, "message": comments})
- console.log(JSON.stringify(comments))
- //console.log(comments) //u need to ask for help on stackoverflow.
- }
- })
- })
- authorId:{
- type: ObjectId,
- ref : 'User',
- required: true
- },
- createdAt: {
- type: Date,
- default: Date.now
- }
- var UserSchema = new Schema({
- username: { type: String, required: true, lowercase: true, index: { unique: true } },
- email: { type: String, required: true, index: { unique: true } },
- //password: { type: String, required: true } u forgot the select field.. that z why login was disturbing
- password: {type: String, select: false} //that z why u need postman to test stuff
Add Comment
Please, Sign In to add comment