第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定

Cannot read property 'reply' of null

Comment.findById(_comment.cid,function (err,comment) {
? ? ? ?var reply={
? ? ? ? ? ?from:_comment.from,
? ? ? ? ? ?to:_comment.tid,//點這個頭像的人要回復(fù)給他
? ? ? ? ? ?content:_comment.content
? ? ? ?}
? ? ? ?console.log(_comment.from);
? ? ? ?console.log(_comment.tid);
? ? ? ?console.log(_comment.content);
? ? ? ?console.log(comment+"77777777777");
? ? ? ?comment.reply.push(reply);
? ? ? ?comment.save(function (err,comment) {//
? ? ? ? ? ?if(err){
? ? ? ? ? ? ? ?console.log(err)
? ? ? ? ? ?}
? ? ? ? ? ?res.redirect("/movie/"+movieId)
? ? ? ?})
? ?})

Cannot read property 'reply' of null,一直顯示這個錯誤 console.log(comment+"77777777777");這個comment一直為null,那個大神請教一下

正在回答

2 回答

當(dāng)前cid在數(shù)據(jù)庫中查詢的結(jié)果為null,null沒有方法,所以.reply報錯。

這段代碼我感覺有問題。findbyId應(yīng)該用comment表的頂層_id做參數(shù)查詢我覺得。

0 回復(fù) 有任何疑惑可以回復(fù)我~

if (!!_comment.cid) {

? ? ? ? Comment.findById(_comment.cid, function(err, comment) {

? ? ? ? ? ? var reply = {

? ? ? ? ? ? ? ? from: _comment.from,

? ? ? ? ? ? ? ? to: _comment.tid,

? ? ? ? ? ? ? ? content: _comment.content

? ? ? ? ? ? }

? ? ? ? ? ? // comment.reply.push(reply)

? ? ? ? ? ? // $addToSet: 不允許重復(fù); $push: 可以重復(fù)

? ? ? ? ? ? comment.update({$addToSet: {reply: reply}}, function(err, comment) {

? ? ? ? ? ? ? ? if (err) {

? ? ? ? ? ? ? ? ? ? console.log(err)

? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? console.log('@@@@' + comment)

? ? ? ? ? ? ? ? res.redirect('/movie/' + movieId)

? ? ? ? ? ? })

? ? ? ? })

? ? } else {

? ? ? ? var comment = new Comment(_comment)


? ? ? ? comment.save(function(err, comment) {

? ? ? ? ? ? if (err) {

? ? ? ? ? ? ? ? console.log(err)

? ? ? ? ? ? }

? ? ? ? ? ? res.redirect('/movie/' + movieId)

? ? ? ? })

? ? }

新版的MongoDB在需要往數(shù)組中添加數(shù)據(jù)時,使用push方法會報$pushAll錯誤。要使用$push或者是$addToSet來實現(xiàn),兩者的區(qū)別是$push可以重復(fù),而$addToSet不能重復(fù)。

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

jly啊啊

這個沒用啊 提示說update undefined
2018-01-29 回復(fù) 有任何疑惑可以回復(fù)我~

舉報

0/150
提交
取消
node建站攻略(二期)——網(wǎng)站升級
  • 參與學(xué)習(xí)       51926    人
  • 解答問題       420    個

幫助你深入前后端開發(fā)留下的迷惑,為進(jìn)一步自學(xué)打下基礎(chǔ)

進(jìn)入課程

Cannot read property 'reply' of null

我要回答 關(guān)注問題
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號