问题
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