JavaScript Interface for Views

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

Address of a View

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

Usage

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

Create a view with default properties:

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

Show execution results

Hide execution results

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

Get this view again later by name:

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

Show execution results

Hide execution results

  1. [ArangoView 88757, "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. "writebufferActive" : 0,
  14. "consolidationIntervalMsec" : 10000,
  15. "cleanupIntervalStep" : 2,
  16. "commitIntervalMsec" : 1000,
  17. "links" : {
  18. }
  19. }

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" : 10000,
  5. "consolidationPolicy" : {
  6. "type" : "tier",
  7. "segmentsBytesFloor" : 2097152,
  8. "segmentsBytesMax" : 5368709120,
  9. "segmentsMax" : 10,
  10. "segmentsMin" : 1,
  11. "minScore" : 0
  12. },
  13. "primarySort" : [ ],
  14. "writebufferActive" : 0,
  15. "writebufferIdle" : 64,
  16. "writebufferSizeMax" : 33554432,
  17. "links" : {
  18. }
  19. }

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" : 10000,
  5. "consolidationPolicy" : {
  6. "type" : "tier",
  7. "segmentsBytesFloor" : 2097152,
  8. "segmentsBytesMax" : 5368709120,
  9. "segmentsMax" : 10,
  10. "segmentsMin" : 1,
  11. "minScore" : 0
  12. },
  13. "primarySort" : [ ],
  14. "writebufferActive" : 0,
  15. "writebufferIdle" : 64,
  16. "writebufferSizeMax" : 33554432,
  17. "links" : {
  18. "colA" : {
  19. "analyzers" : [
  20. "identity"
  21. ],
  22. "fields" : {
  23. },
  24. "includeAllFields" : true,
  25. "storeValues" : "none",
  26. "trackListPositions" : false
  27. }
  28. }
  29. }

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" : 10000,
  5. "consolidationPolicy" : {
  6. "type" : "tier",
  7. "segmentsBytesFloor" : 2097152,
  8. "segmentsBytesMax" : 5368709120,
  9. "segmentsMax" : 10,
  10. "segmentsMin" : 1,
  11. "minScore" : 0
  12. },
  13. "primarySort" : [ ],
  14. "writebufferActive" : 0,
  15. "writebufferIdle" : 64,
  16. "writebufferSizeMax" : 33554432,
  17. "links" : {
  18. "colA" : {
  19. "analyzers" : [
  20. "identity"
  21. ],
  22. "fields" : {
  23. },
  24. "includeAllFields" : true,
  25. "storeValues" : "none",
  26. "trackListPositions" : false
  27. },
  28. "colB" : {
  29. "analyzers" : [
  30. "identity"
  31. ],
  32. "fields" : {
  33. "text" : {
  34. }
  35. },
  36. "includeAllFields" : false,
  37. "storeValues" : "none",
  38. "trackListPositions" : false
  39. }
  40. }
  41. }

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" : 10000,
  5. "consolidationPolicy" : {
  6. "type" : "tier",
  7. "segmentsBytesFloor" : 2097152,
  8. "segmentsBytesMax" : 5368709120,
  9. "segmentsMax" : 10,
  10. "segmentsMin" : 1,
  11. "minScore" : 0
  12. },
  13. "primarySort" : [ ],
  14. "writebufferActive" : 0,
  15. "writebufferIdle" : 64,
  16. "writebufferSizeMax" : 33554432,
  17. "links" : {
  18. "colB" : {
  19. "analyzers" : [
  20. "identity"
  21. ],
  22. "fields" : {
  23. "text" : {
  24. }
  25. },
  26. "includeAllFields" : false,
  27. "storeValues" : "none",
  28. "trackListPositions" : false
  29. }
  30. }
  31. }

Drop the view:

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

Show execution results

Hide execution results

  1.