@@ -5,7 +5,7 @@ The _EdgeCollection API_ extends the
55
66## edgeCollection.document
77
8- ` async edgeCollection.document(documentHandle, [graceful ]): Object `
8+ ` async edgeCollection.document(documentHandle, [opts ]): Object `
99
1010Alias: ` edgeCollection.edge ` .
1111
@@ -19,32 +19,50 @@ Retrieves the edge with the given _documentHandle_ from the collection.
1919 of an edge in the collection, or an edge (i.e. an object with an ` _id ` or
2020 ` _key ` property).
2121
22- * ** graceful** : ` boolean ` (Default: ` false ` )
22+ - ** opts** : ` Object ` (optional)
23+
24+ If _ opts_ is set, it must be an object with any of the following properties:
25+
26+ - ** graceful** : ` boolean ` (Default: ` false ` )
27+
28+ If set to ` true ` , the method will return ` null ` instead of throwing an
29+ error if the edge does not exist.
2330
24- If set to ` true ` , the method will return ` null ` instead of throwing an error
25- if the edge does not exist.
31+ - ** allowDirtyRead** : ` boolean ` (Default: ` false ` )
32+
33+ {% hint 'info' %}
34+ This option is only available when targeting ArangoDB 3.4 or later,
35+ see [ Compatibility] ( ../../GettingStarted/README.md#compatibility ) .
36+ {% endhint %}
37+
38+ If set to ` true ` , the request will explicitly permit ArangoDB to return a
39+ potentially dirty or stale result and arangojs will load balance the
40+ request without distinguishing between leaders and followers.
41+
42+ If a boolean is passed instead of an options object, it will be interpreted as
43+ the _ graceful_ option.
2644
2745** Examples**
2846
2947``` js
3048const db = new Database ();
31- const collection = db .edgeCollection (' edges' );
49+ const collection = db .edgeCollection (" edges" );
3250
33- const edge = await collection .document (' some-key' );
51+ const edge = await collection .document (" some-key" );
3452// the edge exists
35- assert .equal (edge ._key , ' some-key' );
36- assert .equal (edge ._id , ' edges/some-key' );
53+ assert .equal (edge ._key , " some-key" );
54+ assert .equal (edge ._id , " edges/some-key" );
3755
3856// -- or --
3957
40- const edge = await collection .document (' edges/some-key' );
58+ const edge = await collection .document (" edges/some-key" );
4159// the edge exists
42- assert .equal (edge ._key , ' some-key' );
43- assert .equal (edge ._id , ' edges/some-key' );
60+ assert .equal (edge ._key , " some-key" );
61+ assert .equal (edge ._id , " edges/some-key" );
4462
4563// -- or --
4664
47- const edge = await collection .document (' some-key' , true );
65+ const edge = await collection .document (" some-key" , true );
4866if (edge === null ) {
4967 // the edge does not exist
5068}
@@ -68,9 +86,9 @@ Checks whether the edge with the given _documentHandle_ exists.
6886
6987``` js
7088const db = new Database ();
71- const collection = db .edgeCollection (' my-docs' );
89+ const collection = db .edgeCollection (" my-docs" );
7290
73- const exists = await collection .documentExists (' some-key' );
91+ const exists = await collection .documentExists (" some-key" );
7492if (exists === false ) {
7593 // the edge does not exist
7694}
@@ -139,28 +157,28 @@ the _returnNew_ option.
139157
140158``` js
141159const db = new Database ();
142- const collection = db .edgeCollection (' edges' );
143- const data = {some: ' data' };
160+ const collection = db .edgeCollection (" edges" );
161+ const data = { some: " data" };
144162
145163const info = await collection .save (
146164 data,
147- ' vertices/start-vertex' ,
148- ' vertices/end-vertex'
165+ " vertices/start-vertex" ,
166+ " vertices/end-vertex"
149167);
150- assert .equal (info ._id , ' edges/' + info ._key );
151- const edge = await collection .edge (edge)
168+ assert .equal (info ._id , " edges/" + info ._key );
169+ const edge = await collection .edge (edge);
152170assert .equal (edge ._key , info ._key );
153171assert .equal (edge ._rev , info ._rev );
154172assert .equal (edge .some , data .some );
155- assert .equal (edge ._from , ' vertices/start-vertex' );
156- assert .equal (edge ._to , ' vertices/end-vertex' );
173+ assert .equal (edge ._from , " vertices/start-vertex" );
174+ assert .equal (edge ._to , " vertices/end-vertex" );
157175
158176// -- or --
159177
160178const info = await collection .save ({
161- some: ' data' ,
162- _from: ' verticies/start-vertex' ,
163- _to: ' vertices/end-vertex'
179+ some: " data" ,
180+ _from: " verticies/start-vertex" ,
181+ _to: " vertices/end-vertex"
164182});
165183// ...
166184```
@@ -183,16 +201,16 @@ Retrieves a list of all edges of the document with the given _documentHandle_.
183201
184202``` js
185203const db = new Database ();
186- const collection = db .edgeCollection (' edges' );
204+ const collection = db .edgeCollection (" edges" );
187205await collection .import ([
188- [' _key' , ' _from' , ' _to' ],
189- [' x ' , ' vertices/a' , ' vertices/b' ],
190- [' y ' , ' vertices/a' , ' vertices/c' ],
191- [' z ' , ' vertices/d' , ' vertices/a' ]
192- ])
193- const edges = await collection .edges (' vertices/a' );
206+ [" _key" , " _from" , " _to" ],
207+ [" x " , " vertices/a" , " vertices/b" ],
208+ [" y " , " vertices/a" , " vertices/c" ],
209+ [" z " , " vertices/d" , " vertices/a" ]
210+ ]);
211+ const edges = await collection .edges (" vertices/a" );
194212assert .equal (edges .length , 3 );
195- assert .deepEqual (edges .map (edge => edge ._key ), [' x ' , ' y ' , ' z ' ]);
213+ assert .deepEqual (edges .map (edge => edge ._key ), [" x " , " y " , " z " ]);
196214```
197215
198216## edgeCollection.inEdges
@@ -214,16 +232,16 @@ _documentHandle_.
214232
215233``` js
216234const db = new Database ();
217- const collection = db .edgeCollection (' edges' );
235+ const collection = db .edgeCollection (" edges" );
218236await collection .import ([
219- [' _key' , ' _from' , ' _to' ],
220- [' x ' , ' vertices/a' , ' vertices/b' ],
221- [' y ' , ' vertices/a' , ' vertices/c' ],
222- [' z ' , ' vertices/d' , ' vertices/a' ]
237+ [" _key" , " _from" , " _to" ],
238+ [" x " , " vertices/a" , " vertices/b" ],
239+ [" y " , " vertices/a" , " vertices/c" ],
240+ [" z " , " vertices/d" , " vertices/a" ]
223241]);
224- const edges = await collection .inEdges (' vertices/a' );
242+ const edges = await collection .inEdges (" vertices/a" );
225243assert .equal (edges .length , 1 );
226- assert .equal (edges[0 ]._key , ' z ' );
244+ assert .equal (edges[0 ]._key , " z " );
227245```
228246
229247## edgeCollection.outEdges
@@ -245,16 +263,16 @@ _documentHandle_.
245263
246264``` js
247265const db = new Database ();
248- const collection = db .edgeCollection (' edges' );
266+ const collection = db .edgeCollection (" edges" );
249267await collection .import ([
250- [' _key' , ' _from' , ' _to' ],
251- [' x ' , ' vertices/a' , ' vertices/b' ],
252- [' y ' , ' vertices/a' , ' vertices/c' ],
253- [' z ' , ' vertices/d' , ' vertices/a' ]
268+ [" _key" , " _from" , " _to" ],
269+ [" x " , " vertices/a" , " vertices/b" ],
270+ [" y " , " vertices/a" , " vertices/c" ],
271+ [" z " , " vertices/d" , " vertices/a" ]
254272]);
255- const edges = await collection .outEdges (' vertices/a' );
273+ const edges = await collection .outEdges (" vertices/a" );
256274assert .equal (edges .length , 2 );
257- assert .deepEqual (edges .map (edge => edge ._key ), [' x ' , ' y ' ]);
275+ assert .deepEqual (edges .map (edge => edge ._key ), [" x " , " y " ]);
258276```
259277
260278## edgeCollection.traversal
@@ -288,17 +306,17 @@ contained in this edge collection.
288306
289307``` js
290308const db = new Database ();
291- const collection = db .edgeCollection (' edges' );
309+ const collection = db .edgeCollection (" edges" );
292310await collection .import ([
293- [' _key' , ' _from' , ' _to' ],
294- [' x ' , ' vertices/a' , ' vertices/b' ],
295- [' y ' , ' vertices/b' , ' vertices/c' ],
296- [' z ' , ' vertices/c' , ' vertices/d' ]
311+ [" _key" , " _from" , " _to" ],
312+ [" x " , " vertices/a" , " vertices/b" ],
313+ [" y " , " vertices/b" , " vertices/c" ],
314+ [" z " , " vertices/c" , " vertices/d" ]
297315]);
298- const result = await collection .traversal (' vertices/a' , {
299- direction: ' outbound' ,
300- visitor: ' result.vertices.push(vertex._key);' ,
301- init: ' result.vertices = [];'
316+ const result = await collection .traversal (" vertices/a" , {
317+ direction: " outbound" ,
318+ visitor: " result.vertices.push(vertex._key);" ,
319+ init: " result.vertices = [];"
302320});
303- assert .deepEqual (result .vertices , [' a ' , ' b ' , ' c ' , ' d ' ]);
321+ assert .deepEqual (result .vertices , [" a " , " b " , " c " , " d " ]);
304322```
0 commit comments