MrDuDuDu
MrDuDuDu

Reputation: 634

Why in ArangoDB module.context.collection return null

I'm trying to learn how to develop Foxx services.

There are many examples where people use:

const someCollection = module.context.collection('someCollectionName');

But in my project this code doesn't work. someCollection always null, but it's exist in collections.

And this code works perfectly:

const db = require('@arangodb').db;
const someCollection = db._collection('someCollectionName');

My question is why first code isn't work?

Upvotes: 1

Views: 120

Answers (1)

dothebart
dothebart

Reputation: 6077

Foxx services are intended to have their own collections, and being able to be installeable multiple times.

Thus module.context.collection('someCollectionName'); will give you a collection prefixed with the mountpoint of your Foxx-Service, wheres db._collection('someCollectionName'); will always give you the same collection name regardles of which installation of this foxx services you are in - thus several installations may interfere each other.

The easiest way to get started with a complete example that has collections and simple code stubs for manipulation is to choose this clickpath in the UI:

Services -> Add Service=> New

And fill

'someCollectionName' into Document Collections:

Upvotes: 0

Related Questions