我有这样的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!');
}
});
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句