Mongoose $ push的问题

我真的只需要在这里第二套眼睛。 我正在使用Mongoose npm在MongoDB中创build一个新条目。 然后我在Async npm的几个函数中使用这个新的入口。

我遇到的问题是,我得到的前三个控制台日志,“击球手”,“创build”,“req.body.campaign_id”,但没有任何过去。 我认为它必须在我的第一个findByIdAndUpdate $推。 请参阅下面的代码和架构。

码! 请参阅asynchronous并行“活动”function

Bid.create(req.body, function(err, bid){ console.log('create') async.parallel({ campaign: function(done) { console.log(req.body.campaign_id) Camapaign.findByIdAndUpdate(req.body.campaign_id, { $push: { bids: bid._id } }, { safe: true, upsert: true }, function(err, campaign){ console.log('camp', 2) if(err) { console.log(err) done(err) } else { done(null, campaign) } }); }, user: function(done) { console.log('user', 1) User.findByIdAndUpdate(req.body.user_id, { $push: {'bids': bid._id } }, { safe: true, upsert: true }, function(err, bid){ console.log('user', 2) if(err) { done(err) } else { done(null, bid) } }); } }, function(err, response){ console.log('response') if(err) { console.log(err) } else { res.status(200).send(response); } }); }) 

广告系列架构

 var campaignSchema = new mongoose.Schema({ title:String, imgUrl:[String], shortDesc: { type: String, set: shortenDesc }, longDesc:String, duration: Number, price: Number, desired_price: Number, bids: [{ type: mongoose.Schema.Types.ObjectId, ref: 'bidSchema' }], owner_id: { type: mongoose.Schema.Types.ObjectId, ref: 'userSchema' } }); 

用户架构

 var schema = new mongoose.Schema({ name: String, email: { type: String }, password: { type: String }, salt: { type: String }, twitter: { id: String, username: String, token: String, tokenSecret: String }, facebook: { id: String }, google: { id: String }, campaigns: [campaignSchema], bids: [{type: mongoose.Schema.Types.ObjectId, ref: 'bidSchema'}] }); 

请让我知道,如果你需要看别的。 所有的帮助表示赞赏。

谢谢!

你正在做Camapaign.findByIdAndUpdate你确定Camapaign没有被拼写在那里吗? 不应该是Campaign