javascript - mongoose 不能用獲取的ajax數(shù)據(jù)當(dāng)做查詢條件嗎
問(wèn)題描述
Ques.find({’author’: ’admin’}) .select(’star’) .exec((err, stars) => { if (err) next(err) console.log(stars) });
這樣直接寫(xiě)能夠獲取到author為admin的數(shù)據(jù)。
但是換做ajax的數(shù)據(jù)時(shí), 始終不行
let authors = req.body.author; console.log('服務(wù)器收到一個(gè)Ajax請(qǐng)求,信息為:', authors); console.log(typeof(authors)) // string let auth = authors console.log(auth) // admin Ques.find({’author’: auth}) .select(’star’) .exec((err, stars) => { if (err) next(err) console.log(stars) });
不顯示數(shù)據(jù), 說(shuō)明是沒(méi)有找到這個(gè)用戶
我又這樣試了試
let auth = ’admin’ Ques.find({’author’: auth}) .select(’star’) .exec((err, stars) => { if (err) next(err) console.log(stars) });
這樣也是可以的
ajax請(qǐng)求
let author = XXX; // 動(dòng)態(tài)獲取的 $.ajax({data: {author: author},url: ’/star’,dataType: ’json’,timeout: 2000,type: 'POST',success: function(data){ console.log(data);} });
問(wèn)題解答
回答1:供參考。因?yàn)槭茿JAX調(diào)用過(guò)來(lái)的,把結(jié)果返回到調(diào)用的地方顯示,而不是console打印。
Love MongoDB! Have Fun!
相關(guān)文章:
1. thinkphp3 count()方法必須加上字段?2. python中return 語(yǔ)句與 分支語(yǔ)句連用問(wèn)題3. mysql 5個(gè)left關(guān)鍵 然后再用搜索條件 幾千條數(shù)據(jù)就會(huì)卡,如何解決呢4. python - angular route 與 django urls 沖突怎么解決?5. 這是什么情況???6. 微信內(nèi)網(wǎng)頁(yè)上傳圖片問(wèn)題7. 非root安裝MySQL5.6報(bào)錯(cuò),求助!!!8. 輸入地址報(bào)以下截圖錯(cuò)誤,怎么辦?9. node.js - nodejs中mysql子查詢返回多行結(jié)果怎么處理?10. mysql - 瞬間流量很高的網(wǎng)站,要頻繁的插入數(shù)據(jù)到數(shù)據(jù)庫(kù),應(yīng)該怎么解決這個(gè)問(wèn)題?
