0

each time to create service in web interface,a collection named like "xxx_xxx" will be created,question is

 How to create collection named not "xxx_xxx" but "xxx"?
Alex Luya
  • 9,412
  • 15
  • 59
  • 91

1 Answers1

0

Foxx will automatically prefix the name based on the mount path of the service. That's intentionally to avoid conflicts with other services.

You could use a non-prefix "xxx" collection as well if you use the low-level db._collection method to access this collection.

In the corresponding documentation you find suggestions on how to share collections between services as well: https://docs.arangodb.com/3.4/Manual/Foxx/Guides/Collections.html

Example Route /some_products:

router.get('/some_products', function (req, res) {
  res.set("Content-Type", "text/plain; charset=utf-8");

  const { db, aql } = require("@arangodb");
  const query = aql`
    FOR doc IN products
      LIMIT 10
    RETURN doc
  `;
  res.json(db._query(query).toArray());
}
Ingo
  • 159
  • 6
  • Thanks,still,I can't figure out how to make service to use existing table with name like:"camera","user" – Alex Luya Sep 13 '18 at 02:30
  • I have added an example route to the answer. – Ingo Sep 17 '18 at 12:20
  • See the **Sharing collections** section regarding low level access to collections (with no service prefix): https://docs.arangodb.com/3.4/Manual/Foxx/Guides/Collections.html#sharing-collections – CodeManX Oct 16 '18 at 12:49