簡體   English   中英

如何從ArangoDB Foxx應用程序中的集合中讀取數據?

[英]How to read data from collection in an ArangoDB Foxx app?

我有一個名為'user'的集合,其中包含1個文檔:

{
  "username": "test1",
  "password": "pw1",
  "id": "1"
}

我創建了一個Foxx應用程序,並嘗試按照文檔(使用2.6.0a3)。 這是我的控制器:

var Foxx = require('org/arangodb/foxx'),
    usersCollection = applicationContext.collection("user");

var usersRepo = Foxx.Repository.extend({
    getAll: Foxx.createQuery(
        'FOR u IN user RETURN u'
    )
});

var controller = new Foxx.Controller(applicationContext);

controller.get('/', function (req, res) {
    res.json(usersRepo.getAll());
});

我得到: {"error":"undefined is not a function"}而不是記錄列表。

我錯過了什么?

據我所知,對Foxx.Repository.extend()的調用不會實現可用的Repository對象,而是“原型”:

var UsersRepo = Foxx.Repository.extend({
    getAll: Foxx.createQuery(
        'FOR u IN user RETURN u'
    )
});    

似乎缺少的是具體的對象實例:

var usersRepo = new UsersRepo("user");

然后,該實例可用於調用預定義函數:

controller.get('/', function (req, res) {
    res.json(usersRepo.getAll());
});

在上面的代碼,我在名為可變原型UsersRepo (大寫U),並在變量存儲庫對象實例usersRepo (小寫U)。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM