【发布时间】:2016-07-12 11:08:14
【问题描述】:
我有这样的 Mongoose.Schema:
const pixelSchema = mongoose.Schema({
x: String,
y: String,
color: String,
});
我也有这样的对象数组:
let pixels = [
{x: 0, 1: 0, color: 'blue'},
{x: 0, y: 1, color: 'blue'},
{x: 0, y: 2, color: 'blue'},
]
如何检查其中一个元素是否已存在于数据库中? 我的解决方案现在看起来像这样,但我认为它非常低效。
pixels.map(pixel => {
Pixel.find(pixel, (err, pixels) => {
if (pixels) {
console.log('Find!');
}
});
});
【问题讨论】:
标签: javascript node.js mongodb mongoose mongoose-schema