本文介绍了为什么在ArangoDB中module.context.collection返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试学习如何开发Foxx服务.

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

人们使用许多示例:

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-Service的安装点为前缀的集合,其中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.

一个完整的示例(包含集合和简单的代码存根进行操作)最简单的入门方法是在用户界面中选择以下点击路径:

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

然后填充

'someCollectionName'转换为Document Collections:

这篇关于为什么在ArangoDB中module.context.collection返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 21:48