---
feature_story: FS_56_43_05_79
feature_title: search diff collection
feature_status: TEST
---

TODO: Do we need this FS doc if we have FS_45_08_22_15 `index_model` API?
      TODO: At least update the content - it might have already been outdated.

# Feature description

To load data, `argrelay` server can use multiple MongoDB collections - see `MongoClientWrapper.store_envelopes`.

Each collection is characterized by its own set of `index_prop`-s - see FS_45_08_22_15 `index_model`.

It is possible to use the same collection for `data_envelope`-s with different `envelope_class`-es
as long as they all will be searched by the same (super) set of `index_prop`-s.
But, normally, each `envelope_class` is loaded into its own collection.

# `class_name` vs `collection_name`

If `collection_name` is often (and can likely be always) matches `class_name` of all `data_envelope`-s,
why do we need to have `class_name`?

See FS_45_08_22_15 `index_model` API.

# Plugin behavior

*   Where `PluginType.LoaderPlugin` loads its `envelope_class`-es should be agreed with `PluginType.DelegatorPlugin`.

*   During the data load, `PluginType.LoaderPlugin` selects MongoDB collection name for its `envelope_class`-es:
    *   see `EnvelopeCollection`
    *   see `IndexModel`

*   During requests, `PluginType.DelegatorPlugin` provides MongoDB collection name via FS_31_70_49_15 `search_control`.

# Additional benefits

This avoids the hardest limitation of MongoDB (not applicable for `mongomock`):
number of indexes per collection = 64
https://www.mongodb.com/docs/manual/reference/limits/#mongodb-limit-Number-of-Indexes-per-Collection
See: `test_MongoClient_index_limits.py`

This will also reduce latency in for seemingly non-important use cases with `mongomock` instead of real Mongo DB.
But `mongomock` is expected to be the default choice (majority of small installations).

It also enables us to set up different handling for different collections.
Some of them might be too big to re-populate on re-start (too long).

# See also

Original issue: https://github.com/argrelay/argrelay/issues/10

[single_mongo_collection]: https://github.com/argrelay/argrelay/blob/f4c6a6fb9e5cb1226137c3744dd71693ae12c051/src/argrelay/mongo_data/MongoClientWrapper.py#L32
