(MongoDB) How to use AbstractMongoDBListener (Example)

What is MongoListener?
This is eventListener when MongoDB collections has been changed it can help developer do something ( after saving mongodb, elastisearch works next...etc)

First of all,  i will show you methods in AbstractMongoDBListener
If you want to read detail, you can find it springMongoDB Document.
==================================================
void onAfterConvert(AfterConvertEvent<E> event)


void onAfterDelete(AfterDeleteEvent<E> event)


void onAfterLoad(AfterLoadEvent<E> event)


void onAfterSave(AfterSaveEvent<E> event)


void onApplicationEvent(MongoMappingEvent<E> event)


void onBeforeConvert(AfterConvertEvent<E> event)


void onSave(AfterSaveEvent<E> event)
=====================================================================

example)

I will show you how to use onSave method with overriding
This example is  for Listener class when an event is occured from example class


class ExampleListener extends AbstracMongoListener<Example> {


@Override
public void onAfterSave(AfterSaveEvent<Example> event) {

  Example ex = event.getSource();

 //from next, a developer can do anything what they want..


}

you need to care about this
insert, insertList, save method is called and then onAfterSave is worked well,
when you used updateFirst, updateMulti, findAndmodify methods, (onAfterSave method doesn`t worked)

Because their characterstic is different.
updateFirst, updateMulti, findAndmodify method worked in DB
But insert, insertList, save methods are related to Application and when event is occured,
the application can find what event is occured and where event is occured more easily.




댓글

이 블로그의 인기 게시물

(ElasticSearch) 결과에서 순서 정렬

(네트워크)폴링방식 vs 롱 폴링방식

(18장) WebSocekt과 STOMP를 사용하여 메시징하기