Skip to content

How it works

kaiso edited this page Jun 14, 2018 · 1 revision

How RelMongo works

When RelMongo is enabled it will register a custom listener on database operations. Depending on whether the driver is loading or saving objects, RelMongo will process the relations.

  • Loading associations:

When loading an object, RelMongo checks if a supported annotation is present on attributes and makes the associated query in the database to fill the child objects, note that RelMongo makes a query for every association even if the child attribute is of type Collection it loads all the objects in one shot.

RelMongo supports both EAGER and LAZY fetching.

  • On EAGER fetching, all the child association is fetched on loading.

  • On LAZY fetching, the child association is loaded only when it is used.

  • Saving associations:

When saving an object, RelMongo checks if a supported annotation is present, it will only stores two fields of the child object:

  • _id : the object MongoDB id
  • _relmongo_target : the referenced collection