I try to filter my outcome from MongoDB. I'm using an Express. Here are my console.logs:
- {personalbest:{'$gt':'170'},name:{'$gt':'M'}}
- { personalbest: { '$gt': '170' }, name: { '$gt': 'M' } }
Code:
var filters = req.query.filters
db.collection('skijumper').find(filters).toArray()
And of course I get this error:
MongoError: query selector must be an object
What is the best way to convert this req.query to an object ? Thanks
Frontend:
var filters = {personalbest:{'$gt':'170'},name:{'$gt':'M'}};
var url = "http://localhost:3000/test?filters=" + encodeURIComponent(JSON.stringify(filters));
Backend:
var filters = JSON.parse(req.query.filters);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.