问题描述
我正在使用 spring-data 将我们的应用程序与 Mongodb 集成.在其中一个用例中,我调用
I'm using spring-data to Integrate our application with Mongodb. In one of the use-cases, I invoke
MongoOperation.updateMulti(query, set.., Lead.class)
MongoOperation.updateMulti(query, set.., Lead.class)
更新我们的 mongo 集合中的一组文档的方法.我还注册了一个侦听器 bean,它扩展 AbstractMongoEventListener 来侦听此特定 Collection(Lead) 上的事件,如下所示
method to update a set of documents in our mongo collection. I also have a Listener bean registered that extends AbstractMongoEventListener to listen to events on this particular Collection(Lead) as follows
public class LeadListener extends AbstractMongoEventListener<Lead> {
@Override
public void onBeforeSave(Lead p, com.mongodb.DBObject dbo) {
//do something
}
@Override
public void onBeforeConvert(Lead p) {
//do something
}
}
我观察到在执行 mongoOperation.updateMulti 时这些方法都没有被触发,但是在执行 mongoOperation.save(lead) 时它们会被调用.
I observed that none of these methods get fired when mongoOperation.updateMulti is executed, but they get called when mongoOperation.save(lead) is executed.
我可以用于此 updateMulti/update 操作的等效侦听器方法是什么.
What is the equivalent listener method that I can use for this updateMulti/update operation.
推荐答案
如果您查看源代码,updateMulti 会调用 doUpdate 方法,该方法不包含任何侦听器 mayEmitEvent(...) 的触发器.
If you take a look into the source code, updateMulti calls the doUpdate method, which does not contain any triggers of listeners maybeEmitEvent(...).
与 doRemove-Method 相比,它在移除时调用事件.
Compared to the doRemove-Method, which calls events on remove.
似乎有点不一致.
这篇关于什么是与 updateMulti mongooperation 等效的 AbstractMongoEventListener 方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!