gpt4 book ai didi

node.js - 从mongoDB删除记录时,elastics不会与其同步

转载 作者:行者123 更新时间:2023-12-03 00:10:40 24 4
gpt4 key购买 nike

有人请告诉我为什么不同步我的mogoosastic和mongodb?
当我从mongoDB删除记录时,仍然可以看到记录,直到重新启动服务器为止。这是我的搜索功能

exports.search = function (req, res) {
if (!req.query.q) return res.status(400).send('No Query Provided')
log.error(req.query.q)

var query = {
query_string: {
filtered: {
query: {
multi_match: {query: req.query.q,}
},
filter: {term: {isDeleted: false}
}
}
}
}

User.search(query, (err, results) => {
if (err) return handleError1(res, err)
var ret = _.map(results.hits.hits, result => ({
userID: result._id,
_score: result._score,
name: result._source.name,
loc: result._source.loc,
info: result._source.info,
images: result._source.images,
}))
return res.send(ret)
})
}

这是我的Schema声明
isDeleted: {type: Boolean, required: true, default: false, es_indexed: true}

这段代码有什么问题...

最佳答案

我添加了这一行代码,一切正常

.then(groups => {
return User.findById(uid).exec()
})
.then(user => {
let email = user.credentials.loginEmail + '_' + moment().format('YYYYMMDDEHHmmss')
if(app.get('env') === 'localtest') {
email = user.credentials.loginEmail + '_deleted'
}
user.credentials.loginEmail = email;
user.isDeleted = true;
user.updated.at = new Date();
user.save()
.then(user_ =>{
user.sendInfoUpdate()
return res.status(204).send()
})
.catch(err => {
return handleError(res, err)
})
})
.catch(err => {
return handleError(res, err)
})

关于node.js - 从mongoDB删除记录时,elastics不会与其同步,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40975866/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com