使用节点js

时间:2017-01-18 10:57:16

标签: node.js mongodb mongoose

我想获取与派对相关的所有评论,我有以下代码,然后如何将两个集合合并为单个集合并将其呈现为ejs文件。

PartySchema:

var partySchema = mongoose.Schema({
    user_id: String,
    category: { type: String, ref: 'categories' },
    reviews: [{ type: String, ref: 'reviews' }],
    title: String,
    description: String,
    location: String,
    latitude: String,
    longitude: String,
    contact_no: Number,
    price: Number,
    email: String,
    website: String,
    video_url: String,
    facebook_url: String,
    twitter_url: String,
    youtube_url: String,
    pinterest_url: String,
    images: [{}],
    startdate: String,
    enddate: String,
    starttime: String,
    endtime: String,
    price: Number,
    duration: Number
});

ReviewSchema:

var reviewSchema = mongoose.Schema({
    user : { type: String, ref: 'users' },
    party : { type: String, ref: 'parties' },
    title: String,
    content: String
});

Route.js

app.get("/admin/ManageParties",isLoggedIn, function (req, res) {               
Party.find({}).populate('category').populate('reviews')
     .exec(function(err,_parties){
             for(var i in _parties){
                Review.find({party:_parties[i]._id},function(err,_rev){
                    console.log(_rev);
                })                
             }            
             res.render('admin/manageparties',{
                _p:_parties
             })
        })
});

0 个答案:

没有答案