gpt4 book ai didi

node.js - Mongoose $push 的问题

转载 作者:太空宇宙 更新时间:2023-11-04 00:51:59 25 4
gpt4 key购买 nike

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

我遇到的问题是我收到了前三个控制台日志,“hitter”、“create”和“req.body.campaign_id”,但除此之外什么都没有。我认为这与我在第一个 findByIdAndUpdate 中的 $push 有关。请参阅下面我的代码和架构。

代码!查看异步并行“事件”功能

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 没有拼写错误吗?难道不应该是广告事件吗?

关于node.js - Mongoose $push 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31992273/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com