javascript - mongoose 不能用獲取的ajax數(shù)據(jù)當(dāng)做查詢條件嗎
問題描述
Ques.find({’author’: ’admin’}) .select(’star’) .exec((err, stars) => { if (err) next(err) console.log(stars) });
這樣直接寫能夠獲取到author為admin的數(shù)據(jù)。
但是換做ajax的數(shù)據(jù)時, 始終不行
let authors = req.body.author; console.log('服務(wù)器收到一個Ajax請求,信息為:', 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ù), 說明是沒有找到這個用戶
我又這樣試了試
let auth = ’admin’ Ques.find({’author’: auth}) .select(’star’) .exec((err, stars) => { if (err) next(err) console.log(stars) });
這樣也是可以的
ajax請求
let author = XXX; // 動態(tài)獲取的 $.ajax({data: {author: author},url: ’/star’,dataType: ’json’,timeout: 2000,type: 'POST',success: function(data){ console.log(data);} });
問題解答
回答1:供參考。因為是AJAX調(diào)用過來的,把結(jié)果返回到調(diào)用的地方顯示,而不是console打印。
Love MongoDB! Have Fun!
相關(guān)文章:
1. docker-machine添加一個已有的docker主機(jī)問題2. angular.js - angularjs的自定義過濾器如何給文字加顏色?3. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。4. 關(guān)于docker下的nginx壓力測試5. 為什么我ping不通我的docker容器呢???6. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.7. nignx - docker內(nèi)nginx 80端口被占用8. docker - 如何修改運(yùn)行中容器的配置9. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題10. docker鏡像push報錯
