JavaScript Interface for Views

This is an introduction to ArangoDB’s interface for views and how to handle views from the JavaScript shell arangosh. For other languages see the corresponding language API.

Address of a View

Like collections, views are accessed by the user via their unique name and internally via their identifier. Using the identifier for accessing views is discouraged. Views share their namespace with collections, so there cannot exist a view and a collection with the same name in the same database.

Usage

Here follow some basic usage examples. More details can be found in the following chapters:

Create a view with default properties:

  1. arangosh> view = db._createView("myView", "arangosearch", {});

Show execution results

Hide execution results

  1. [ArangoView 81054, "myView" (type arangosearch)]

Get this view again later by name:

  1. arangosh> view = db._view("myView");

Show execution results

Hide execution results

  1. [ArangoView 81054, "myView" (type arangosearch)]

Get the view properties:

  1. arangosh> view.properties();

Show execution results

Hide execution results

  1. {
  2. "writebufferIdle" : 64,
  3. "writebufferSizeMax" : 33554432,
  4. "consolidationPolicy" : {
  5. "type" : "tier",
  6. "segmentsBytesFloor" : 2097152,
  7. "segmentsBytesMax" : 5368709120,
  8. "segmentsMax" : 10,
  9. "segmentsMin" : 1,
  10. "minScore" : 0
  11. },
  12. "primarySort" : [ ],
  13. "storedValues" : [ ],
  14. "writebufferActive" : 0,
  15. "consolidationIntervalMsec" : 1000,
  16. "cleanupIntervalStep" : 2,
  17. "commitIntervalMsec" : 1000,
  18. "links" : {
  19. },
  20. "primarySortCompression" : "lz4"
  21. }

Set a view property:

  1. arangosh> view.properties({cleanupIntervalStep: 12});

Show execution results

Hide execution results

  1. {
  2. "cleanupIntervalStep" : 12,
  3. "commitIntervalMsec" : 1000,
  4. "consolidationIntervalMsec" : 1000,
  5. "consolidationPolicy" : {
  6. "type" : "tier",
  7. "segmentsBytesFloor" : 2097152,
  8. "segmentsBytesMax" : 5368709120,
  9. "segmentsMax" : 10,
  10. "segmentsMin" : 1,
  11. "minScore" : 0
  12. },
  13. "primarySort" : [ ],
  14. "primarySortCompression" : "lz4",
  15. "storedValues" : [ ],
  16. "writebufferActive" : 0,
  17. "writebufferIdle" : 64,
  18. "writebufferSizeMax" : 33554432,
  19. "links" : {
  20. }
  21. }

Add a link:

  1. arangosh> view.properties({links: {colA: {includeAllFields: true}}});

Show execution results

Hide execution results

  1. {
  2. "cleanupIntervalStep" : 12,
  3. "commitIntervalMsec" : 1000,
  4. "consolidationIntervalMsec" : 1000,
  5. "consolidationPolicy" : {
  6. "type" : "tier",
  7. "segmentsBytesFloor" : 2097152,
  8. "segmentsBytesMax" : 5368709120,
  9. "segmentsMax" : 10,
  10. "segmentsMin" : 1,
  11. "minScore" : 0
  12. },
  13. "primarySort" : [ ],
  14. "primarySortCompression" : "lz4",
  15. "storedValues" : [ ],
  16. "writebufferActive" : 0,
  17. "writebufferIdle" : 64,
  18. "writebufferSizeMax" : 33554432,
  19. "links" : {
  20. "colA" : {
  21. "analyzers" : [
  22. "identity"
  23. ],
  24. "fields" : {
  25. },
  26. "includeAllFields" : true,
  27. "storeValues" : "none",
  28. "trackListPositions" : false
  29. }
  30. }
  31. }

Add another link:

  1. arangosh> view.properties({links: {colB: {fields: {text: {}}}}});

Show execution results

Hide execution results

  1. {
  2. "cleanupIntervalStep" : 12,
  3. "commitIntervalMsec" : 1000,
  4. "consolidationIntervalMsec" : 1000,
  5. "consolidationPolicy" : {
  6. "type" : "tier",
  7. "segmentsBytesFloor" : 2097152,
  8. "segmentsBytesMax" : 5368709120,
  9. "segmentsMax" : 10,
  10. "segmentsMin" : 1,
  11. "minScore" : 0
  12. },
  13. "primarySort" : [ ],
  14. "primarySortCompression" : "lz4",
  15. "storedValues" : [ ],
  16. "writebufferActive" : 0,
  17. "writebufferIdle" : 64,
  18. "writebufferSizeMax" : 33554432,
  19. "links" : {
  20. "colA" : {
  21. "analyzers" : [
  22. "identity"
  23. ],
  24. "fields" : {
  25. },
  26. "includeAllFields" : true,
  27. "storeValues" : "none",
  28. "trackListPositions" : false
  29. },
  30. "colB" : {
  31. "analyzers" : [
  32. "identity"
  33. ],
  34. "fields" : {
  35. "text" : {
  36. }
  37. },
  38. "includeAllFields" : false,
  39. "storeValues" : "none",
  40. "trackListPositions" : false
  41. }
  42. }
  43. }

Remove the first link again:

  1. arangosh> view.properties({links: {colA: null}});

Show execution results

Hide execution results

  1. {
  2. "cleanupIntervalStep" : 12,
  3. "commitIntervalMsec" : 1000,
  4. "consolidationIntervalMsec" : 1000,
  5. "consolidationPolicy" : {
  6. "type" : "tier",
  7. "segmentsBytesFloor" : 2097152,
  8. "segmentsBytesMax" : 5368709120,
  9. "segmentsMax" : 10,
  10. "segmentsMin" : 1,
  11. "minScore" : 0
  12. },
  13. "primarySort" : [ ],
  14. "primarySortCompression" : "lz4",
  15. "storedValues" : [ ],
  16. "writebufferActive" : 0,
  17. "writebufferIdle" : 64,
  18. "writebufferSizeMax" : 33554432,
  19. "links" : {
  20. "colB" : {
  21. "analyzers" : [
  22. "identity"
  23. ],
  24. "fields" : {
  25. "text" : {
  26. }
  27. },
  28. "includeAllFields" : false,
  29. "storeValues" : "none",
  30. "trackListPositions" : false
  31. }
  32. }
  33. }

Drop the view:

  1. arangosh> db._dropView("myView");

Show execution results

Hide execution results