What is the AbstractMongoEventListener method equivalent for updateMulti mongooperation

◇◆丶佛笑我妖孽 提交于 2019-12-12 18:24:33

问题


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)

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
    }
}

I observed that none of these methods get fired when mongoOperation.updateMulti is executed, but they get called when mongoOperation.save(lead) is executed.

What is the equivalent listener method that I can use for this updateMulti/update operation.


回答1:


https://github.com/spring-projects/spring-data-mongodb/blob/master/spring-data-mongodb/src/main/java/org/springframework/data/mongodb/core/MongoTemplate.java?source=c

If you take a look into the source code, updateMulti calls the doUpdate method, which does not contain any triggers of listeners maybeEmitEvent(...).

Compared to the doRemove-Method, which calls events on remove.

It seems there is a slightly little inconsistency.



来源:https://stackoverflow.com/questions/26913431/what-is-the-abstractmongoeventlistener-method-equivalent-for-updatemulti-mongoop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!