Working with collections
The prefixes may initially feel unnecessarily verbose but help avoid conflicts between different services with similar collection names or even multiple copies of the same service sharing the same database. Keep in mind that you can also use collection objects when writing queries, so you don’t need to worry about writing out prefixes by hand.
As a rule of thumb you should always use module.context.collection
to access collections in your service.
Using these methods requires you to work with fully qualified collection names. This means instead of using to get a collection object you need to use module.context.collectionName
to get the prefixed collection name ArangoDB understands:
Sharing collections
The most obvious way to share collections between multiple services is to use an unprefixed collection name and then use the low-level db._collection
method to access that collection from each service that needs access to it.
The cleanest approach is to instead decide on a single service which manages the collection and set up explicit dependencies between the different services using the collection:
const users = module.dependencies.usersService.users;
This approach not only makes the dependency on an externally managed collection explicit but also allows having those services still use different collections if necessary by providing multiple copies of the service that provides the shared collection.