Skip to content

Commit 7bfca37

Browse files
authored
Update MIGRATING.md (#823)
* chore: add v6 to v7 migration steps * fix: typo in route example
1 parent c13259a commit 7bfca37

File tree

2 files changed

+354
-1
lines changed

2 files changed

+354
-1
lines changed

MIGRATING.md

Lines changed: 353 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -618,3 +618,356 @@ using the `db.collections` and `collection.truncate` methods:
618618
+ db.collections().map((collection) => collection.truncate())
619619
+);
620620
```
621+
622+
623+
## v6 to v7
624+
625+
### Configuration changes
626+
627+
The `db.useDatabase` method has been deprecated in v7.
628+
629+
Previously the primary use of this method was to set the database name of the
630+
arangojs instance. The database name can now be specified using the
631+
`databaseName` option in the arangojs configuration:
632+
633+
```diff
634+
const db = new Database({
635+
url: "http://localhost:8529",
636+
+ databaseName: "my_database",
637+
});
638+
-db.useDatabase("my_database");
639+
```
640+
641+
### Shared connection pool
642+
643+
It is now possible to have multiple `Database` objects using the same
644+
underlying connection pool:
645+
646+
```diff
647+
-const db1 = new Database();
648+
-db1.useDatabase("database1");
649+
-const db2 = new Database();
650+
-db2.useDatabase("database2");
651+
+const db1 = new Database({ databaseName: "database1" });
652+
+const db2 = db1.database("database2");
653+
```
654+
655+
### Indexes
656+
657+
The helper methods for creating specific index types, e.g. `createHashIndex`,
658+
have been removed and replaced with the generic `ensureIndex` method (which
659+
was previously called `createIndex`):
660+
661+
```diff
662+
-await collection.createGeoIndex(["lat", "lng"]);
663+
+await collection.createIndex({ type: "geo", fields: ["lat", "lng"] });
664+
```
665+
666+
### Document and edge collections
667+
668+
Version 7 no longer provides different methods for accessing document and edge
669+
collections as both types are now implemented using the same underlying class:
670+
671+
```diff
672+
const myDocumentCollection = db.collection("documents");
673+
-const myEdgeCollection = db.edgeCollection("edges");
674+
+const myEdgeCollection = db.collection("edges");
675+
```
676+
677+
When using TypeScript the collection instances can still be cast to the more
678+
specific `DocumentCollection` and `EdgeCollection` interfaces:
679+
680+
```ts
681+
interface EdgeType {
682+
color: string;
683+
}
684+
const myEdgeCollection = db.collection("edges") as EdgeCollection<EdgeType>;
685+
```
686+
687+
### Saving edge documents
688+
689+
The `save` method no longer supports positional arguments for `_from` and `_to`
690+
values. These now need to be supplied as part of the document data:
691+
692+
```diff
693+
await edges.save(
694+
- "vertices/start",
695+
- "vertices/end",
696+
- { color: "red" }
697+
+ { _from: "vertices/start", _to: "vertices/end", color: "red" }
698+
);
699+
```
700+
701+
### Accessing documents
702+
703+
The `edge` method has been removed from the low-level collection API as it was
704+
an alias for the `document` method, which still exists:
705+
706+
```diff
707+
-const edges = db.edgeCollection("edges");
708+
+const edges = db.collection("edges");
709+
710+
-const edge = await edges.edge("my-edge");
711+
+const edge = await edges.document("my-edge");
712+
```
713+
714+
Graph vertex and edge collections instead only retain their specific `vertex`
715+
and `edge` methods which access the collection using the high-level graph API:
716+
717+
```diff
718+
const vertices = graph.vertexCollection("vertices");
719+
-const vertex = await vertices.document("my-vertex");
720+
+const vertex = await vertices.vertex("my-vertex");
721+
722+
const edges = graph.edgeCollection("edges");
723+
-const edge = await edges.document("my-edge");
724+
+const edge = await edges.edge("my-edge");
725+
```
726+
727+
### Graph collections
728+
729+
Graph vertex and edge collections no longer implement the generic collection
730+
API methods to avoid confusion between operations that are aware of the graph
731+
definition (and can trigger graph-related side-effects) and those that directly
732+
access low-level operations.
733+
734+
As a convenience both graph collection types still provide access to the
735+
low-level collection interface via the `collection` property:
736+
737+
```diff
738+
const graphEdges = graph.edgeCollection("edges");
739+
-const outEdges = graphEdges.outEdges("vertices/start");
740+
+const outEdges = graphEdges.collection.outEdges("vertices/start");
741+
```
742+
743+
### Cursor methods
744+
745+
The method `each` is now called `forEach`. The method `hasNext` has been
746+
replaced with a getter.
747+
748+
The methods `some` and `every` have been removed. These methods previously
749+
allowed iterating over cursor results in order to derive a boolean value by
750+
applying a callback function to each value in the result.
751+
752+
In most cases these methods can be avoided by writing a more efficient AQL
753+
query:
754+
755+
```diff
756+
-const cursor = await db.query(aql`
757+
- FOR bowl IN porridges
758+
- RETURN bowl
759+
-`);
760+
-const someJustRight = await cursor.some(
761+
- (bowl) => bowl.temperature < TOO_HOT && bowl.temperature > TOO_COLD
762+
-);
763+
+const cursor = await db.query(aql`
764+
+ FOR bowl IN porridges
765+
+ FILTER bowl.temperature < ${TOO_HOT}
766+
+ FILTER bowl.temperature > ${TOO_COLD}
767+
+ LIMIT 1
768+
+ RETURN 1
769+
+`);
770+
+const someJustRight = Boolean(await cursor.next());
771+
```
772+
773+
If this is not an option, the old behavior can be emulated using the `forEach`
774+
method (previously called `each`) instead:
775+
776+
```diff
777+
-const someJustRight = await cursor.some(
778+
- (bowl) => bowl.temperature < TOO_HOT && bowl.temperature > TOO_COLD
779+
-);
780+
+const someJustRight = !(await cursor.forEach(
781+
+ (bowl) => bowl.temperature === TOO_HOT || bowl.temperature === TOO_COLD
782+
+));
783+
```
784+
785+
### Batch cursor API
786+
787+
Cursors now provide a low-level API for iterating over the result batches
788+
instead of individual items, which is exposed via the `batches` property.
789+
790+
The methods `hasMore` and `nextBatch` have been replaced with the getter
791+
`batches.hasMore` and the method `batches.next`:
792+
793+
```diff
794+
-if (cursor.hasMore()) {
795+
- return await cursor.nextBatch();
796+
+if (cursor.batches.hasMore) {
797+
+ return await cursor.batches.next();
798+
}
799+
```
800+
801+
### Simple queries
802+
803+
Collection methods for using simple queries (e.g. `all`, `any` and `list`)
804+
have been deprecated in ArangoDB 3.0 and are now also deprecated in arangojs.
805+
806+
See the documentation of each method for an example for how to perform the same
807+
query using an AQL query instead.
808+
809+
Additionally the `list` method now returns a cursor instead of an array.
810+
811+
### ArangoSearch Views
812+
813+
The database methods `arangoSearchView` and `createArangoSearchView` have been
814+
renamed to `view` and `createView` respectively as there currently is no other
815+
view type available in ArangoDB:
816+
817+
```diff
818+
-await db.createArangoSearchView("my-view");
819+
-const view = db.arangoSearchView("my-view");
820+
+await db.createView("my-view");
821+
+const view = db.view("my-view");
822+
```
823+
824+
### Query options
825+
826+
The `options` argument of `db.query` has been flattened. Options that were
827+
previously nested in an `options` property of that argument are now specified
828+
directly on the argument itself:
829+
830+
```diff
831+
const cursor = await db.query(
832+
aql`
833+
FOR doc IN ${collection}
834+
RETURN doc
835+
`,
836+
{
837+
cache: false,
838+
- options: { fullCount: true },
839+
+ fullCount: true,
840+
}
841+
);
842+
```
843+
844+
### Bulk imports
845+
846+
The default value of the `type` option now depends on the input type instead
847+
of always defaulting to `"auto"`. If you previously relied on the default
848+
value being set to `"auto"`, you may now need to explicitly set this option:
849+
850+
```diff
851+
-await collection.import(data);
852+
+await collection.import(data, { type: "auto" });
853+
```
854+
855+
### Bulk operations
856+
857+
The collection method `bulkUpdate` has been removed and the methods
858+
`save`, `update`, `replace` and `remove` no longer accept arrays as input.
859+
860+
Bulk operations can now be performed using the dedicated methods
861+
`saveAll`, `updateAll`, `replaceAll` and `removeAll`:
862+
863+
```diff
864+
-await collection.save([{ _key: "a" }, { _key: "b" }]);
865+
+await collection.saveAll([{ _key: "a" }, { _key: "b" }]);
866+
```
867+
868+
### Cross-collection operations
869+
870+
Collection methods no longer accept document IDs from other collections.
871+
Previously passing a document ID referring to a different collection would
872+
result in the collection performing a request to that collection instead. Now
873+
mismatching IDs will result in an error instead:
874+
875+
```js
876+
const collection1 = db.collection("collection1");
877+
const doc = await collection1.document("collection2/xyz"); // ERROR
878+
```
879+
880+
### Creating graphs
881+
882+
The signatures of `db.createGraph` and `graph.create` have changed to always
883+
take an array of edge definitions as the first argument instead of taking the
884+
edge definitions as a property of the `properties` argument.
885+
886+
Additionally the `properties` and `options` arguments have been merged:
887+
888+
```diff
889+
await graph.create(
890+
+ [{ collection: "edges", from: ["a"], to: ["b"] }],
891+
{
892+
- edgeDefinitions: [{ collection: "edges", from: ["a"], to: ["b"] }],
893+
isSmart: true,
894+
- },
895+
- {
896+
waitForSync: true,
897+
}
898+
);
899+
```
900+
901+
### Transactions
902+
903+
The transaction method `run` has been renamed to `step` to make it more obvious
904+
that it is intended to only perform a single "step" of the transaction.
905+
906+
See the method's documentation for examples of how to use the method correctly.
907+
908+
Additionally the method `transaction` no longer acts as an alias for
909+
`executeTransaction`:
910+
911+
```diff
912+
-const result = await db.transaction(collections, action);
913+
+const result = await db.executeTransaction(collections, action);
914+
```
915+
916+
### Service development mode
917+
918+
The methods `enableServiceDevelopmentMode` and `disableServiceDevelopmentMode`
919+
have been replaced with the method `setServiceDevelopmentMode`:
920+
921+
```diff
922+
-await db.enableServiceDevelopmentMode("/my-foxx");
923+
+await db.setServiceDevelopmentMode("/my-foxx", true);
924+
```
925+
926+
### System services
927+
928+
The default value of the method `listServices` option `excludeSystem` has been
929+
changed from `false` to `true`:
930+
931+
```diff
932+
-const services = await db.listServices(true);
933+
+const services = await db.listServices();
934+
```
935+
936+
### Query tracking
937+
938+
The method `setQueryTracking` has been merged into `queryTracking`:
939+
940+
```diff
941+
-await db.setQueryTracking({ enabled: true });
942+
+await db.queryTracking({ enabled: true });
943+
```
944+
945+
### Collection properties
946+
947+
The method `setProperties` has been merged into `properties`:
948+
949+
```diff
950+
-await collection.setProperties({ waitForSync: true });
951+
+await collection.properties({ waitForSync: true });
952+
```
953+
954+
### View properties
955+
956+
The View method `setProperties` has been renamed to `updateProperties`:
957+
958+
```diff
959+
-await view.setProperties({ consolidationIntervalMsec: 234 });
960+
+await view.updateProperties({ consolidationIntervalMsec: 234 });
961+
```
962+
963+
### Truncating collections
964+
965+
The `db.truncate` method has been removed. The behavior can still be mimicked
966+
using the `db.collections` and `collection.truncate` methods:
967+
968+
```diff
969+
-await db.truncate();
970+
+await Promise.all(
971+
+ db.collections().map((collection) => collection.truncate())
972+
+);
973+
```

src/routes.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export class Route {
142142
* ```js
143143
* const db = new Database();
144144
* const foxx = db.route("/my-foxx-service");
145-
* const user = foxx.roue("/users/admin");
145+
* const user = foxx.route("/users/admin");
146146
* const res = await user.delete();
147147
* ```
148148
*/

0 commit comments

Comments
 (0)