mongoosastic findOneAndUpdate 没有在 elasticsearch 中建立索引
mongoosastic findOneAndUpdate not indexing in elasticsearch
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 选项将 return 更新或创建对象,因此内部 mongoosastic 工作就像插入对象或更新对象 return 然后它会插入弹性搜索索引
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'
});
}
});
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 选项将 return 更新或创建对象,因此内部 mongoosastic 工作就像插入对象或更新对象 return 然后它会插入弹性搜索索引
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'
});
}
});