javascript - mongoose 不能用獲取的ajax數(shù)據(jù)當做查詢條件嗎
問題描述
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('服務器收到一個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)用過來的,把結果返回到調(diào)用的地方顯示,而不是console打印。
Love MongoDB! Have Fun!
相關文章:
1. java中返回一個對象,和輸出對像的值,意義在哪兒2. docker網(wǎng)絡端口映射,沒有方便點的操作方法么?3. mysql - 在不允許改動數(shù)據(jù)表的情況下,如何優(yōu)化以varchar格式存儲的時間的比較?4. docker start -a dockername 老是卡住,什么情況?5. css3 - 純css實現(xiàn)點擊特效6. apache web server 怎么限制某一個網(wǎng)站對服務器資源的占用?7. javascript - 關于apply()與call()的問題8. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?9. 安全性測試 - nodejs中如何防m(xù)ySQL注入10. python - pandas dataframe如何對某列的空數(shù)據(jù)位置進行update?update的函數(shù)是自定義的,參數(shù)是同一行的另外兩列數(shù)據(jù)
