问题
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?
回答1:
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:
来源:https://stackoverflow.com/questions/47976621/why-in-arangodb-module-context-collection-return-null