【发布时间】:2019-04-20 04:34:19
【问题描述】:
我需要以下格式的 Mongoose find().exec 的结果。可以这样格式化结果吗?
var myFunction = function(foo, bar) {
model1.find({ elem: foo, elem2: bar }).exec(function(err, data) {
if (err) {
/* ... */
}
if (data) {
if (data.passed == true) {
return { passed: true, point: data.point };
} else {
return { passed: false, point: data.point };
}
} else {
return { passed: false, point: "not tried" };
}
});
};
object = {
...
someitem: array.map(function(arr) {
return {
_id: program._id,
title: program.title,
slug: program.slug,
status: myFunction(arr._id, arr._id2) /* Like This */
};
});
...
}
请原谅我的英语不好:D
【问题讨论】:
-
find(elem:foo,elem2:bar)应该是find({elem:foo,elem2:bar}) -
从数据中,您只返回
{ passed, point}。用户从哪里获得您提到的数组?你的问题到底是什么?