每个人都过得愉快。使用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)
我猜它来自
dbQueries.remove({_id: {$in: {req.body.data}}, authorId: req.user._id}, function onRemoveSomething(err){
if(err) {
res.json({epicFail: 'ERR_RestrictedAccess'});
return;
}
});
所以,我不知道出了什么问题。
答案 0 :(得分:35)
答案 1 :(得分:1)
您必须检查req.body.data
是否为数组,请参阅下面的代码
{_id: {$in: _.isArray(req.body.data) ? req.body.data : [req.body.data] } //const _ = require('lodash');
答案 2 :(得分:0)
根据数据构建查询
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) {
});