Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's wrong with "$in" in mongoose

Good day for everyone. I have a strange error working with mongoose

module.js:437
  var compiledWrapper = runInThisContext(wrapper, filename, tru
                        ^
SyntaxError: Unexpected token .
    at Module._compile (module.js:437:25)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (E:\Dropbox\Dropbox\FCP\server.js
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)

I gues it's goes from

dbQueries.remove({_id: {$in: {req.body.data}}, authorId: req.user._id}, function onRemoveSomething(err){
            if(err) {
                res.json({epicFail: 'ERR_RestrictedAccess'});
                return; 
            }
        });

So, I have no idea what is wrong.

like image 239
Roman Avatar asked Aug 07 '12 05:08

Roman


Video Answer


1 Answers

$in takes an array, not an invalidly formatted javascript object

{_id: {$in: [req.body.data]}

or if req.body.data is already an array, omit the wrapping [ ]

like image 66
Andy Ray Avatar answered Oct 13 '22 21:10

Andy Ray