Problem : In my example if i user schema.save then it will indexed in elastic search
but problem starts when i use findOneAndUpdate so it will not index in elastic even if i insert (i.e save)
MovieSchema.findOneAndUpdate(query, reqObject, {
upsert: true
}, function(err, results) {
if (err) {
if (!update) {
var filePath = path.join(__dirname, "../../movie/images/uploads/") + reqObject.imageUrl;
fs.unlinkSync(filePath);
}
console.log(err)
callback({
RESULT_CODE: '-1',
MESSAGE: 'System error. Please try again'
});
} else {
callback({
RESULT_CODE: '1',
MESSAGE: 'Movie inserted'
});
}
});
最佳答案
我喜欢使用findOneAndUpdate的答案
示例:
NOTE : pass new : true option upsert: true and it will work
New 选项将返回更新或创建的对象,因此内部 mongoosastic 工作就像插入的对象或更新的对象返回,然后它只会插入到 Elasticsearch 索引中
MovieSchema.findOneAndUpdate(query, reqObject, {
upsert: true,'new': true
}, function(err, results) {
if (err) {
callback({
RESULT_CODE: '-1',
MESSAGE: 'System error. Please try again'
});
} else {
callback({
RESULT_CODE: '1',
MESSAGE: 'Movie inserted'
});
}
});
关于node.js - mongoosastic findOneAndUpdate 不在elasticsearch 中建立索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33992359/