Good day for everyone. I have a strange error working with mongoose
每个人都过得愉快我和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.
所以,我不知道出了什么问题。
3 个解决方案
#1
28
$in takes an array, not an invalidly formatted javascript object
$ in采用数组,而不是格式无效的javascript对象
{_id: {$in: [req.body.data]}
or if req.body.data
is already an array, omit the wrapping [
]
或者如果req.body.data已经是一个数组,则省略wrap []
#2
1
you have to check req.body.data
is an array or not, see the code below {_id: {$in: _.isArray(req.body.data) ? req.body.data : [req.body.data] } //const _ = require('lodash');
你必须检查req.body.data是不是数组,请参阅下面的代码{_id:{$ in:_.isArray(req.body.data)? req.body.data:[req.body.data]} // const _ = require('lodash');
#3
0
Build your query based on the data
根据数据构建查询
var match = {
authorId: req.user._id
};
if(Array.isArray(data)) {
match._id = {$in: data};
} else {
match._id = data;
}
dbQueries.remove(match, function findMyDocs(err, foundDocs) {
});
#1
28
$in takes an array, not an invalidly formatted javascript object
$ in采用数组,而不是格式无效的javascript对象
{_id: {$in: [req.body.data]}
or if req.body.data
is already an array, omit the wrapping [
]
或者如果req.body.data已经是一个数组,则省略wrap []
#2
1
you have to check req.body.data
is an array or not, see the code below {_id: {$in: _.isArray(req.body.data) ? req.body.data : [req.body.data] } //const _ = require('lodash');
你必须检查req.body.data是不是数组,请参阅下面的代码{_id:{$ in:_.isArray(req.body.data)? req.body.data:[req.body.data]} // const _ = require('lodash');
#3
0
Build your query based on the data
根据数据构建查询
var match = {
authorId: req.user._id
};
if(Array.isArray(data)) {
match._id = {$in: data};
} else {
match._id = data;
}
dbQueries.remove(match, function findMyDocs(err, foundDocs) {
});