From 8a835b15067e35dc0e66e86026055b9a2b3d4614 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 13:32:29 -0400 Subject: [PATCH 01/10] bump realmjs to 10.5.0-beta-1 --- examples/node/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/node/package.json b/examples/node/package.json index d65139f6e3..a338c12a4d 100644 --- a/examples/node/package.json +++ b/examples/node/package.json @@ -25,7 +25,7 @@ "jest": "^26.5.3", "prettier": "^2.1.2", "random-email": "^1.0.3", - "realm": "^10.0.1", + "realm": "^10.5.0-beta.1", "ts-jest": "^26.4.1", "typescript": "^4.0.3" }, From e22658e4e0abe35d23706394b8d9835c649ecc25 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 13:48:48 -0400 Subject: [PATCH 02/10] removed uuid as it's own page and added a subsection on it --- source/sdk/node/data-types.txt | 2 -- source/sdk/node/data-types/field-types.txt | 30 +++++++++++++++++++++- source/sdk/node/data-types/uuid.txt | 17 ------------ 3 files changed, 29 insertions(+), 20 deletions(-) delete mode 100644 source/sdk/node/data-types/uuid.txt diff --git a/source/sdk/node/data-types.txt b/source/sdk/node/data-types.txt index af7774d7af..1449789cda 100644 --- a/source/sdk/node/data-types.txt +++ b/source/sdk/node/data-types.txt @@ -20,7 +20,6 @@ Realm Data Types - Node.js SDK Dictionaries Sets Mixed - UUID Embedded Objects - :doc:`Field Types ` @@ -28,5 +27,4 @@ Realm Data Types - Node.js SDK - :doc:`Dictionaries ` - :doc:`Sets ` - :doc:`Mixed ` -- :doc:`UUID ` - :doc:`Embedded Objects ` \ No newline at end of file diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index 9037883fa7..1893681c0f 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -21,4 +21,32 @@ Field Types -Node.js SDK - ``objectId`` maps to BSON :manual:`ObjectId ` type. - ``data`` maps to the JavaScript :mdn:`ArrayBuffer ` type. - ``date`` maps to the JavaScript :mdn:`Date ` type. -- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. \ No newline at end of file +- ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. +- ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. + + +ObjectId +-------- + +MongoDB's :manual:`ObjectId ` is 12-byte unique +value. You can use ``ObjectId`` as an identifier for objects. ``ObjectId`` is +:ref:`indexable ` and can be used as a :ref:`primary keys +`. + + +UUID +---- + +.. versionadded:: 10.5.0-beta.1 + +``UUID`` (Universal Unique Identifier) is a 16-byte :wikipedia:`unique value +`. You can use ``UUID`` as an identifier for +objects. ``UUID`` is :ref:`indexable ` and can be used as a +:ref:`primary keys `. Use ``UUID`` by importing +:js-sdk:`Realm.BSON ` and calling ``new UUID()``. + +.. note:: + + If you are migrating data not stored in MongoDB, it is likely that your + object's unique identifiers are of a ``UUID`` type. + diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt deleted file mode 100644 index b0a3a597ab..0000000000 --- a/source/sdk/node/data-types/uuid.txt +++ /dev/null @@ -1,17 +0,0 @@ -.. _node-data-types-uuid: - -================== -UUID - Node.js SDK -================== -.. default-domain:: mongodb - -.. contents:: On this page - :local: - :backlinks: none - :depth: 2 - :class: singlecol - -.. versionadded:: 10.5.0-beta.1 - -Overview --------- \ No newline at end of file From 1dd6490c6d71a8b82296036583e9261d8a837072 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 14:50:28 -0400 Subject: [PATCH 03/10] added uuid bluehawked snippet + readded uuid to toc --- examples/node/Examples/data-types.js | 46 +++++++++++++++++++ .../data-types.codeblock.work-with-uuid.js | 18 ++++++++ source/sdk/node/data-types.txt | 2 + source/sdk/node/data-types/field-types.txt | 9 +++- source/sdk/node/data-types/uuid.txt | 17 +++++++ 5 files changed, 90 insertions(+), 2 deletions(-) create mode 100644 source/examples/generated/node/data-types.codeblock.work-with-uuid.js create mode 100644 source/sdk/node/data-types/uuid.txt diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index 78132c055f..b0a478fe00 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -34,6 +34,42 @@ const BusinessSchema = { }; // :code-block-end: describe("Node.js Data Types", () => { + test("should work with UUID", async () => { + // :code-block-start: work-with-uuid + const { UUID } = Realm.BSON; + const ProfileSchema = { + name: "Profile", + primaryKey: "_id", + properties: { + _id: "uuid", + name: "string", + }, + }; + const realm = await Realm.open({ + schema: [ProfileSchema], + }); + realm.write(() => { + realm.create("Profile", { + name: "John Doe.", + _id: new UUID(), + }); + }); + // :code-block-end: + + const johnDoeProfile = realm + .objects("Profile") + .filtered("name = 'John Doe.'")[0]; + + // test if johnDoeProfile's _id is a valid UUID field + expect(UUID.isValid(johnDoeProfile._id)).toBe(true); + + // delete the objects to keep the tests idempotent + realm.write(() => { + realm.delete(johnDoeProfile); + }); + // close the realm + realm.close(); + }); test("should work with Mixed Type", async () => { // :code-block-start: define-mixed-in-schema const DogSchema = { @@ -86,12 +122,16 @@ describe("Node.js Data Types", () => { const Blaise = realm.objects("Dog").filtered(`name = 'Blaise'`)[0]; const Euclid = realm.objects("Dog").filtered(`name = 'Euclid'`)[0]; const Pythagoras = realm.objects("Dog").filtered(`name = 'Pythagoras'`)[0]; + // delete the objects to keep the tests idempotent realm.write(() => { realm.delete(Euler); realm.delete(Blaise); realm.delete(Euclid); realm.delete(Pythagoras); }); + // close the realm + realm.close(); + }); test("should create and read and delete an embedded object", async () => { const realm = await Realm.open({ schema: [AddressSchema, ContactSchema], @@ -182,5 +222,11 @@ describe("Node.js Data Types", () => { // :code-block-end: expect(harryPotter.address.city).toBe("London"); + // delete the objects to keep the tests idempotent + realm.write(() => { + realm.delete(harryPotter); + }); + // close the realm + realm.close(); }); }); diff --git a/source/examples/generated/node/data-types.codeblock.work-with-uuid.js b/source/examples/generated/node/data-types.codeblock.work-with-uuid.js new file mode 100644 index 0000000000..303d89db08 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.work-with-uuid.js @@ -0,0 +1,18 @@ +const { UUID } = Realm.BSON; +const ProfileSchema = { + name: "Profile", + primaryKey: "_id", + properties: { + _id: "uuid", + name: "string", + }, +}; +const realm = await Realm.open({ + schema: [ProfileSchema], +}); +realm.write(() => { + realm.create("Profile", { + name: "John Doe.", + _id: new UUID(), + }); +}); diff --git a/source/sdk/node/data-types.txt b/source/sdk/node/data-types.txt index 1449789cda..af7774d7af 100644 --- a/source/sdk/node/data-types.txt +++ b/source/sdk/node/data-types.txt @@ -20,6 +20,7 @@ Realm Data Types - Node.js SDK Dictionaries Sets Mixed + UUID Embedded Objects - :doc:`Field Types ` @@ -27,4 +28,5 @@ Realm Data Types - Node.js SDK - :doc:`Dictionaries ` - :doc:`Sets ` - :doc:`Mixed ` +- :doc:`UUID ` - :doc:`Embedded Objects ` \ No newline at end of file diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index 1893681c0f..1a4344a853 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -24,6 +24,7 @@ Field Types -Node.js SDK - ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. - ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. +.. _node-field-types-objectid: ObjectId -------- @@ -33,6 +34,7 @@ value. You can use ``ObjectId`` as an identifier for objects. ``ObjectId`` is :ref:`indexable ` and can be used as a :ref:`primary keys `. +.. _node-field-types-uuid: UUID ---- @@ -42,11 +44,14 @@ UUID ``UUID`` (Universal Unique Identifier) is a 16-byte :wikipedia:`unique value `. You can use ``UUID`` as an identifier for objects. ``UUID`` is :ref:`indexable ` and can be used as a -:ref:`primary keys `. Use ``UUID`` by importing -:js-sdk:`Realm.BSON ` and calling ``new UUID()``. +:ref:`primary keys `. .. note:: If you are migrating data not stored in MongoDB, it is likely that your object's unique identifiers are of a ``UUID`` type. +Usage +~~~~~ + + diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt new file mode 100644 index 0000000000..b0a3a597ab --- /dev/null +++ b/source/sdk/node/data-types/uuid.txt @@ -0,0 +1,17 @@ +.. _node-data-types-uuid: + +================== +UUID - Node.js SDK +================== +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. versionadded:: 10.5.0-beta.1 + +Overview +-------- \ No newline at end of file From c22f3b6743255c2e6d408dc5c963b4f416c7e1c6 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 16:16:18 -0400 Subject: [PATCH 04/10] added uuid examples --- examples/node/Examples/data-types.js | 6 +++++- source/sdk/node/data-types/uuid.txt | 25 ++++++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index b0a478fe00..9dabec8429 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -51,7 +51,11 @@ describe("Node.js Data Types", () => { realm.write(() => { realm.create("Profile", { name: "John Doe.", - _id: new UUID(), + _id: new UUID(), // create a _id with a randomly generated UUID + }); + realm.create("Profile", { + name: "Tim Doe.", + _id: new UUID("882dd631-bc6e-4e0e-a9e8-f07b685fec8c"), // create a _id with a specific UUId value }); }); // :code-block-end: diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index b0a3a597ab..7fc3ae0350 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -14,4 +14,27 @@ UUID - Node.js SDK .. versionadded:: 10.5.0-beta.1 Overview --------- \ No newline at end of file +-------- + +``UUID`` (Universal Unique Identifier) is a 16-byte :wikipedia:`unique value +`. You can use ``UUID`` as an identifier for +objects. ``UUID`` is :ref:`indexable ` and can be used as a +:ref:`primary keys `. + +.. note:: Using UUID Instead of ObjectId + + In general, you can use ``UUID`` in any field that you need a unique + identifier. Using ``UUID`` might be particularly useful if you are migrating + data not stored in MongoDB since it is likely that your object's unique + identifiers are already of a ``UUID`` type + +Usage +----- +To define a property as a ``UUID``, set it's type to the string ``"uuid"`` in +your :ref:`object model `. Create a {+service-short+} +object within a write transaction. To set the unique identifier property to a +random value call ``new UUID()``. Pass a string to ``new UUID()`` to set the +unique identifier property to a specific value. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.work-with-uuid.js + :language: javascript \ No newline at end of file From 9d7e059f971b1e29e2f3046a8785cd395b77ac41 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 16:20:03 -0400 Subject: [PATCH 05/10] removed uuid from field types as a paragraph --- source/sdk/node/data-types/field-types.txt | 30 ---------------------- 1 file changed, 30 deletions(-) diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index 1a4344a853..5dead1e9bf 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -24,34 +24,4 @@ Field Types -Node.js SDK - ``list`` maps to the JavaScript :mdn:`Array ` type. You can also specify that a field contains a list of a primitive value type by appending ``[]`` to the type name. - ``uuid`` is a universally unique identifier from :js-sdk:`Realm.BSON `. -.. _node-field-types-objectid: - -ObjectId --------- - -MongoDB's :manual:`ObjectId ` is 12-byte unique -value. You can use ``ObjectId`` as an identifier for objects. ``ObjectId`` is -:ref:`indexable ` and can be used as a :ref:`primary keys -`. - -.. _node-field-types-uuid: - -UUID ----- - -.. versionadded:: 10.5.0-beta.1 - -``UUID`` (Universal Unique Identifier) is a 16-byte :wikipedia:`unique value -`. You can use ``UUID`` as an identifier for -objects. ``UUID`` is :ref:`indexable ` and can be used as a -:ref:`primary keys `. - -.. note:: - - If you are migrating data not stored in MongoDB, it is likely that your - object's unique identifiers are of a ``UUID`` type. - -Usage -~~~~~ - From 510dd097101b8c44b91184f4726294091cff8c37 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 16:30:13 -0400 Subject: [PATCH 06/10] update wording --- source/sdk/node/data-types/uuid.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index 7fc3ae0350..ee1ab3e085 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -32,9 +32,9 @@ Usage ----- To define a property as a ``UUID``, set it's type to the string ``"uuid"`` in your :ref:`object model `. Create a {+service-short+} -object within a write transaction. To set the unique identifier property to a -random value call ``new UUID()``. Pass a string to ``new UUID()`` to set the -unique identifier property to a specific value. +object within a write transaction. To set any unique identifier properties of +your object to a random value, call ``new UUID()``. Alternatively, set a string +to ``new UUID()`` to set the unique identifier property to a specific value. .. literalinclude:: /examples/generated/node/data-types.codeblock.work-with-uuid.js :language: javascript \ No newline at end of file From b75b2e675c29e51b113d89a332d8a4247b2efa9e Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 16:33:01 -0400 Subject: [PATCH 07/10] update wording --- source/sdk/node/data-types/uuid.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index ee1ab3e085..d965ebcb63 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -19,18 +19,18 @@ Overview ``UUID`` (Universal Unique Identifier) is a 16-byte :wikipedia:`unique value `. You can use ``UUID`` as an identifier for objects. ``UUID`` is :ref:`indexable ` and can be used as a -:ref:`primary keys `. +:ref:`primary key `. .. note:: Using UUID Instead of ObjectId In general, you can use ``UUID`` in any field that you need a unique identifier. Using ``UUID`` might be particularly useful if you are migrating data not stored in MongoDB since it is likely that your object's unique - identifiers are already of a ``UUID`` type + identifiers are already of a ``UUID`` type. Usage ----- -To define a property as a ``UUID``, set it's type to the string ``"uuid"`` in +To define a property as a ``UUID``, set its type to the string ``"uuid"`` in your :ref:`object model `. Create a {+service-short+} object within a write transaction. To set any unique identifier properties of your object to a random value, call ``new UUID()``. Alternatively, set a string From be830bf3057ea13a61fc20aef7cdc044e48bd982 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 16:38:03 -0400 Subject: [PATCH 08/10] fix passive voice --- source/sdk/node/data-types/uuid.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index d965ebcb63..ef0cfaafd3 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -18,7 +18,7 @@ Overview ``UUID`` (Universal Unique Identifier) is a 16-byte :wikipedia:`unique value `. You can use ``UUID`` as an identifier for -objects. ``UUID`` is :ref:`indexable ` and can be used as a +objects. ``UUID`` is :ref:`indexable ` and you can use it as a :ref:`primary key `. .. note:: Using UUID Instead of ObjectId From a1c3e358ef17faf60984b269348819671092258c Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 17:06:14 -0400 Subject: [PATCH 09/10] add specific uuid example --- examples/node/Examples/data-types.js | 2 +- .../generated/node/data-types.codeblock.work-with-uuid.js | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index 9dabec8429..cb9c499945 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -55,7 +55,7 @@ describe("Node.js Data Types", () => { }); realm.create("Profile", { name: "Tim Doe.", - _id: new UUID("882dd631-bc6e-4e0e-a9e8-f07b685fec8c"), // create a _id with a specific UUId value + _id: new UUID("882dd631-bc6e-4e0e-a9e8-f07b685fec8c"), // create a _id with a specific UUID value }); }); // :code-block-end: diff --git a/source/examples/generated/node/data-types.codeblock.work-with-uuid.js b/source/examples/generated/node/data-types.codeblock.work-with-uuid.js index 303d89db08..cea1351927 100644 --- a/source/examples/generated/node/data-types.codeblock.work-with-uuid.js +++ b/source/examples/generated/node/data-types.codeblock.work-with-uuid.js @@ -13,6 +13,10 @@ const realm = await Realm.open({ realm.write(() => { realm.create("Profile", { name: "John Doe.", - _id: new UUID(), + _id: new UUID(), // create a _id with a randomly generated UUID + }); + realm.create("Profile", { + name: "Tim Doe.", + _id: new UUID("882dd631-bc6e-4e0e-a9e8-f07b685fec8c"), // create a _id with a specific UUID value }); }); From b937362fa0b5d2ab47ee755a012e48c680b36a00 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 17 May 2021 15:30:53 -0400 Subject: [PATCH 10/10] removed innacurate collections are homogenous (per mixed) --- source/sdk/node/data-types/collections.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt index 22faee6f5c..07955f3244 100644 --- a/source/sdk/node/data-types/collections.txt +++ b/source/sdk/node/data-types/collections.txt @@ -18,8 +18,7 @@ Overview {+service-short+} has several types to represent groups of objects, which we call **collections**. A collection is an object that contains zero or more instances of one :ref:`{+service-short+} type -`. {+service-short+} collections are **homogenous**: -all objects in a collection are of the same type. +`. You can filter and sort any collection using {+client-database+}'s :ref:`query engine `. Collections are