1

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?

MrDuDuDu
  • 534
  • 5
  • 12
  • 1
    Please provide more context in accordance with the guidelines (http://stackoverflow.com/help/mcve). Have you followed the guidance at https://docs.arangodb.com/3.3/Manual/Foxx/Context.html ? What is your "require" statement? – peak Dec 26 '17 at 22:59

1 Answers1

0

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:

dothebart
  • 5,972
  • 16
  • 40