为什么在ArangoDB module.context.collection中返回null

时间:2017-12-26 09:45:00

标签: arangodb foxx

我正在努力学习如何开发Foxx服务。

人们使用的例子很多:

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

但在我的项目中,这段代码并不起作用。 someCollection总是为null,但它存在于集合中。

这段代码完美无缺:

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

我的问题是为什么第一个代码不起作用?

1 个答案:

答案 0 :(得分: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: