我有这个用于GET查询的Node.js方法
app.get('/:tableName', function(req, res) {
var schema = require('./schema/' + req.param('tableName'));
var q = unescape(Object.keys(req.query)[0]);
console.log('query:' + q);
schema.find(q, function(err, result) {
if (err) {
console.log(err);
res.status(500).json({status: 'failure'});
}
if (result) {
res.json(result);
} else {
res.json({status: 'not found'});
}
});
});
如果我把它叫做白色这个输入的话,那就是..(这正是var q
的价值)
{
"remoteID" : "80E75ED5-B696-446E-9AA7-9B170350D7E6"
}
..我收回了3项但不符合条件,基本上会返回表格中的所有项目。
[{"lastName":"K","remoteID":"D5DC51C1-C415-4073-A647-1D41BB47D03E","password":"p","firstName":"J","email":"xxx","airline":"73C02335-C019-419E-BCC7-C87537F38492","userName":"J","_id":"5353b639889a61000038848c","__v":0},
{"lastName":"asd","remoteID":"C471495C-C218-4440-BA81-7BD37CBB5605","password":"wn831","firstName":"asd","email":"asd@asd.hu","airline":"73C02335-C019-419E-BCC7-C87537F38492","userName":"ASA","_id":"5353b639889a610000388491","__v":0},
{"remoteID":"5A0D51DE-DCD0-4E3E-9D97-7CAD066DB68A","userName":"R","password":"R","_id":"5353b639889a610000388492","__v":0}]
答案 0 :(得分:0)
缺少一条重要的路线:
var jq = JSON.parse(q);
schema.find(jq, function(err, result) {
find()方法不需要字符串而是JSON对象。