为什么在 ArangoDB module.context.collection 中返回 null [英] Why in ArangoDB module.context.collection return null
问题描述
我正在努力学习如何开发 Foxx 服务.
I'm trying to learn how to develop Foxx services.
人们使用的例子有很多:
There are many examples where people use:
const someCollection = module.context.collection('someCollectionName');
但在我的项目中,此代码不起作用.someCollection 始终为 null,但它存在于集合中.
But in my project this code doesn't work. someCollection always null, but it's exist in collections.
这段代码完美运行:
const db = require('@arangodb').db;
const someCollection = db._collection('someCollectionName');
我的问题是为什么第一个代码不起作用?
My question is why first code isn't work?
推荐答案
Foxx 服务旨在拥有自己的集合,并且能够多次安装.
Foxx services are intended to have their own collections, and being able to be installeable multiple times.
因此 module.context.collection('someCollectionName');
会给你一个以你的 Foxx 服务的挂载点为前缀的集合,其中 db._collection('someCollectionName');
将始终为您提供相同的集合名称,无论您安装的是哪个 Foxx 服务 - 因此多个安装可能会相互干扰.
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.
开始使用具有集合和用于操作的简单代码存根的完整示例的最简单方法是在 UI 中选择此点击路径:
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
-> 添加服务
=> New
并填充
'someCollectionName'
到 Document Collections:
这篇关于为什么在 ArangoDB module.context.collection 中返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!