CCPony CCPony - 2 months ago 10
Javascript Question

MassiveJS strange casting error

I'm new to Massive, but I really like it. While using

and making a very simple db call:

router.get('/:id', function(req, res, next) {
db.accounts.find(, 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(, 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"}.