I'm new to Massive, but I really like it. While using express.Router()
and making a very simple db call:
router.get('/:id', function(req, res, next) {
db.accounts.find(req.params.id, function(err, results) {...});
I obtained an error:
Error: Argument 0 (conditions) should be type Object, but it was type string with value 2. at Args (C:\\Users\\JMichelson\\WebstormProjects\\Proximityv6\\node_modules\\args-js\\Args.js:399:10) at Object.exports.forArgs (C:\\Users\\JMichelson\\WebstormProjects\\Proximityv6\\node_modules\\massive\\lib\\arg_types.js:7 7:10) ...
Which was resolved with a simple cast:
router.get('/:id', function(req, res, next) {
db.accounts.find(Number(req.params.id), function(err, results) {...});
But I find that this casting requirement to be strange since JavaScript should automatically cast as necessary.
Am I doing this correctly?
I believe that find wants a number and the params come in as a string so the args parser gets confused. You can use int.parse
here or do what you're doing. Massive is a bit opinionated in this regard: you can use string keys if you want but you'll have to be specific with `{id:"my string"}.
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.