Search code examples
javascriptarangodbfoxx

ArangoDB/FOXX repositories issue


I'm trying a custom query in a repository on a FOXX app in ArangoDB:

        /*clinics.js */  

         'use strict'; 

    var Foxx = require('org/arangodb/foxx');

            var ClinicsRepository = Foxx.Repository.extend({   
// Add your custom methods here

              //Returns all procedures from a clinic, given the clinic id 
getAllProcedures: Foxx.createQuery({
                    query: 'FOR clinic IN exameFacil_clinics FILTER clinic._key == [@id] RETURN clinic.procedures',

                    params: ['id']

                })
 });

            exports.repository = ClinicsRepository;

I did this following the Foxx cookbook, but it always gives me an error:

[ArangoError 3103: failed to invoke module File: c:/Program Files/ArangoDB 2.6.2/var/lib/arangodb-apps/_db/_system/exameFacil/APP/controllers/clinics.js]

[ArangoError
3103: failed to invoke module File: c:/Program Files/ArangoDB
2.6.2/var/lib/arangodb-apps/_db/_system/exameFacil/APP/controllers/clinics.js]
at [object Object].Module.run (C:\Program Files\ArangoDB
2.6.2\bin../share/arangodb/js/common/bootstrap/modules.js:1420:20)   at ArangoApp.loadAppScript (c:/Program Files/ArangoDB
2.6.2/share/arangodb/js/server/modules/org/arangodb/foxx/arangoApp.js:452:24)
at mountController (c:/Program Files/ArangoDB
2.6.2/share/arangodb/js/server/modules/org/arangodb/foxx/routing.js:661:7)
at c:/Program Files/ArangoDB
2.6.2/share/arangodb/js/server/modules/org/arangodb/foxx/routing.js:630:9
at Array.forEach (native)   at routeApp (c:/Program Files/ArangoDB
2.6.2/share/arangodb/js/server/modules/org/arangodb/foxx/routing.js:629:32)
at Object.routes (c:/Program Files/ArangoDB
2.6.2/share/arangodb/js/server/modules/org/arangodb/foxx/manager.js:268:10)
at foxxRouting (c:/Program Files/ArangoDB
2.6.2/share/arangodb/js/server/modules/org/arangodb/actions.js:1054:74)
at execute (c:/Program Files/ArangoDB
2.6.2/share/arangodb/js/server/modules/org/arangodb/actions.js:1308:7)   at Object.routeRequest (c:/Program Files/ArangoDB
2.6.2/share/arangodb/js/server/modules/org/arangodb/actions.js:1329:3)   at Function.actions.defineHttp.callback (c:\Program Files\ArangoDB
2.6.2\share\arangodb\js\actions\api-system.js:58:15) 

This error occurs anytime I try to 'require' the clinics.js file. Any suggestions? Thank you!


Solution

  • Can you try changing the line

    exports.repository = ClinicsRepository;
    

    to

    module.exports = ClinicsRepository;
    

    Then the error should go away.

    Apart from that, the filter in the AQL query may need to be changed from

    FILTER clinic._key == [@id]
    

    to

    FILTER clinic._key == @id
    

    or

    FILTER clinic._key IN @id
    

    to actually find a document, depending on whether you want to find a single document or an array of documents.