Akhila Lankala
Akhila Lankala

Reputation: 203

What is the AbstractMongoEventListener method equivalent for updateMulti mongooperation

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.

Upvotes: 2

Views: 2692

Answers (1)

Martin Baumgartner
Martin Baumgartner

Reputation: 3652

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.

Upvotes: 1

Related Questions