From 849b6266efca0929dcc7613b074d23a0bdc8a2ac Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 5 May 2021 20:55:22 -0400 Subject: [PATCH 1/9] New data types node rn (#1040) * new data types for node * added data types to TOC Co-authored-by: Mohammad Hunan Chughtai --- source/sdk/node.txt | 1 + source/sdk/node/data-types.txt | 29 +++++++++++++++++++ source/sdk/node/data-types/collections.txt | 16 ++++++++++ source/sdk/node/data-types/dictionaries.txt | 18 ++++++++++++ .../sdk/node/data-types/embedded-objects.txt | 13 +++++++++ source/sdk/node/data-types/field-types.txt | 16 ++++++++++ source/sdk/node/data-types/mixed.txt | 17 +++++++++++ source/sdk/node/data-types/sets.txt | 18 ++++++++++++ source/sdk/node/data-types/uuid.txt | 17 +++++++++++ 9 files changed, 145 insertions(+) create mode 100644 source/sdk/node/data-types/collections.txt create mode 100644 source/sdk/node/data-types/dictionaries.txt create mode 100644 source/sdk/node/data-types/embedded-objects.txt create mode 100644 source/sdk/node/data-types/field-types.txt create mode 100644 source/sdk/node/data-types/mixed.txt create mode 100644 source/sdk/node/data-types/sets.txt create mode 100644 source/sdk/node/data-types/uuid.txt diff --git a/source/sdk/node.txt b/source/sdk/node.txt index 71100930c5..c205fa7d31 100644 --- a/source/sdk/node.txt +++ b/source/sdk/node.txt @@ -12,6 +12,7 @@ MongoDB Realm Node.js SDK Quick Start Quick Start with Sync Fundamentals + Data Types Usage Examples Integration Guides Advanced Guides diff --git a/source/sdk/node/data-types.txt b/source/sdk/node/data-types.txt index 983cc3d950..af7774d7af 100644 --- a/source/sdk/node/data-types.txt +++ b/source/sdk/node/data-types.txt @@ -1,3 +1,32 @@ +.. _node-data-types: + ============================== Realm Data Types - Node.js SDK ============================== +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +.. toctree:: + :titlesonly: + :hidden: + + Field Types + Collections + Dictionaries + Sets + Mixed + UUID + Embedded Objects + +- :doc:`Field Types ` +- :doc:`Collections ` +- :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/collections.txt b/source/sdk/node/data-types/collections.txt new file mode 100644 index 0000000000..bf8be9eead --- /dev/null +++ b/source/sdk/node/data-types/collections.txt @@ -0,0 +1,16 @@ +.. _node-collections: + +========================= +Collections - Node.js SDK +========================= + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + +Overview +-------- \ No newline at end of file diff --git a/source/sdk/node/data-types/dictionaries.txt b/source/sdk/node/data-types/dictionaries.txt new file mode 100644 index 0000000000..de4a5419d3 --- /dev/null +++ b/source/sdk/node/data-types/dictionaries.txt @@ -0,0 +1,18 @@ +.. _node-dictionaries: + +========================== +Dictionaries - 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 diff --git a/source/sdk/node/data-types/embedded-objects.txt b/source/sdk/node/data-types/embedded-objects.txt new file mode 100644 index 0000000000..53d6e002b7 --- /dev/null +++ b/source/sdk/node/data-types/embedded-objects.txt @@ -0,0 +1,13 @@ +.. _node-embedded-objects: + +============================== +Embedded Objects - Node.js SDK +============================== + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt new file mode 100644 index 0000000000..e3685b3eb4 --- /dev/null +++ b/source/sdk/node/data-types/field-types.txt @@ -0,0 +1,16 @@ +.. _node-field-types: + +========================= +Field Types - Node.js SDK +========================= + +.. default-domain:: mongodb + +.. contents:: On this page + :local: + :backlinks: none + :depth: 2 + :class: singlecol + + +{+client-database+} supports the following field data types: diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt new file mode 100644 index 0000000000..4c2748f733 --- /dev/null +++ b/source/sdk/node/data-types/mixed.txt @@ -0,0 +1,17 @@ +.. _node-mixed: + +=================== +Mixed - 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 diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt new file mode 100644 index 0000000000..513981ba76 --- /dev/null +++ b/source/sdk/node/data-types/sets.txt @@ -0,0 +1,18 @@ +.. _node-sets: + +================== +Sets - 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 diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt new file mode 100644 index 0000000000..739a842f36 --- /dev/null +++ b/source/sdk/node/data-types/uuid.txt @@ -0,0 +1,17 @@ +.. _node-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 d9d42cd4b5ba3af04ba74ffb34b6f23a9ee34a6e Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Wed, 5 May 2021 23:13:45 -0400 Subject: [PATCH 2/9] fixed refs for node.js data types --- source/sdk/node/data-types/collections.txt | 2 +- source/sdk/node/data-types/dictionaries.txt | 2 +- source/sdk/node/data-types/embedded-objects.txt | 2 +- source/sdk/node/data-types/field-types.txt | 2 +- source/sdk/node/data-types/mixed.txt | 2 +- source/sdk/node/data-types/sets.txt | 2 +- source/sdk/node/data-types/uuid.txt | 2 +- 7 files changed, 7 insertions(+), 7 deletions(-) diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt index bf8be9eead..d754879064 100644 --- a/source/sdk/node/data-types/collections.txt +++ b/source/sdk/node/data-types/collections.txt @@ -1,4 +1,4 @@ -.. _node-collections: +.. _node-data-types-collections: ========================= Collections - Node.js SDK diff --git a/source/sdk/node/data-types/dictionaries.txt b/source/sdk/node/data-types/dictionaries.txt index de4a5419d3..b0dc026ce2 100644 --- a/source/sdk/node/data-types/dictionaries.txt +++ b/source/sdk/node/data-types/dictionaries.txt @@ -1,4 +1,4 @@ -.. _node-dictionaries: +.. _node-data-types-dictionaries: ========================== Dictionaries - Node.js SDK diff --git a/source/sdk/node/data-types/embedded-objects.txt b/source/sdk/node/data-types/embedded-objects.txt index 53d6e002b7..c1ff8fd4cb 100644 --- a/source/sdk/node/data-types/embedded-objects.txt +++ b/source/sdk/node/data-types/embedded-objects.txt @@ -1,4 +1,4 @@ -.. _node-embedded-objects: +.. _node-data-types-embedded-objects: ============================== Embedded Objects - Node.js SDK diff --git a/source/sdk/node/data-types/field-types.txt b/source/sdk/node/data-types/field-types.txt index e3685b3eb4..f9b36305cc 100644 --- a/source/sdk/node/data-types/field-types.txt +++ b/source/sdk/node/data-types/field-types.txt @@ -1,4 +1,4 @@ -.. _node-field-types: +.. _node-data-types-field-types: ========================= Field Types - Node.js SDK diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt index 4c2748f733..06a5d9b3fa 100644 --- a/source/sdk/node/data-types/mixed.txt +++ b/source/sdk/node/data-types/mixed.txt @@ -1,4 +1,4 @@ -.. _node-mixed: +.. _node-data-types-mixed: =================== Mixed - Node.js SDK diff --git a/source/sdk/node/data-types/sets.txt b/source/sdk/node/data-types/sets.txt index 513981ba76..5dc7b5b845 100644 --- a/source/sdk/node/data-types/sets.txt +++ b/source/sdk/node/data-types/sets.txt @@ -1,4 +1,4 @@ -.. _node-sets: +.. _node-data-types-sets: ================== Sets - Node.js SDK diff --git a/source/sdk/node/data-types/uuid.txt b/source/sdk/node/data-types/uuid.txt index 739a842f36..b0a3a597ab 100644 --- a/source/sdk/node/data-types/uuid.txt +++ b/source/sdk/node/data-types/uuid.txt @@ -1,4 +1,4 @@ -.. _node-uuid: +.. _node-data-types-uuid: ================== UUID - Node.js SDK From 765c5113f60d67b1f8b9b27a6ea9d1998a671c84 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 6 May 2021 10:21:40 -0400 Subject: [PATCH 3/9] update doc --- source/sdk/node/data-types/collections.txt | 30 +++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt index d754879064..d6072bd327 100644 --- a/source/sdk/node/data-types/collections.txt +++ b/source/sdk/node/data-types/collections.txt @@ -13,4 +13,32 @@ Collections - Node.js SDK :class: singlecol Overview --------- \ No newline at end of file +-------- + +{+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 +:ref:`live `, so they always reflect the current state +of the :term:`{+realm+} instance` on the current thread. You can also +listen for changes in the collection by subscribing to :ref:`collection +notifications `. + +Lists +----- + + +Overview +Lists & LinkingObjects +Results Collection +Results are Lazily Evaluated +Collections are Live +Working With Collections + Iteration + Limiting Query Results + Pagination +Summary \ No newline at end of file From bbc78176af7129eb220440eb698fe5ff2e7082b7 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 6 May 2021 10:22:41 -0400 Subject: [PATCH 4/9] Remove accidental changes --- source/sdk/node/data-types/collections.txt | 28 ---------------------- 1 file changed, 28 deletions(-) diff --git a/source/sdk/node/data-types/collections.txt b/source/sdk/node/data-types/collections.txt index d6072bd327..f0675fafbd 100644 --- a/source/sdk/node/data-types/collections.txt +++ b/source/sdk/node/data-types/collections.txt @@ -14,31 +14,3 @@ Collections - Node.js SDK 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 -:ref:`live `, so they always reflect the current state -of the :term:`{+realm+} instance` on the current thread. You can also -listen for changes in the collection by subscribing to :ref:`collection -notifications `. - -Lists ------ - - -Overview -Lists & LinkingObjects -Results Collection -Results are Lazily Evaluated -Collections are Live -Working With Collections - Iteration - Limiting Query Results - Pagination -Summary \ No newline at end of file From 905430875e97ff6a2204ae3222a3bb5200694c91 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Thu, 6 May 2021 15:48:44 -0400 Subject: [PATCH 5/9] added empty test file --- examples/node/Examples/data-types.js | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 examples/node/Examples/data-types.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js new file mode 100644 index 0000000000..dd899119fe --- /dev/null +++ b/examples/node/Examples/data-types.js @@ -0,0 +1,4 @@ +import Realm from "realm"; + +describe("Node.js Data Types", () => { +}) \ No newline at end of file From f3ae7813e80d71de41534559e0dfa7fc2cba1f74 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 10 May 2021 08:13:46 -0400 Subject: [PATCH 6/9] attempt to add bluehawked mixed example snippets --- examples/node/Examples/data-types.js | 60 ++++++++++++++++++- ...eblock.create-objects-with-mixed-values.js | 20 +++++++ ...-types.codeblock.define-mixed-in-schema.js | 7 +++ ...deblock.query-objects-with-mixed-values.js | 3 + source/sdk/node/data-types/mixed.txt | 50 +++++++++++++++- 5 files changed, 138 insertions(+), 2 deletions(-) create mode 100644 source/examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js create mode 100644 source/examples/generated/node/data-types.codeblock.define-mixed-in-schema.js create mode 100644 source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index dd899119fe..4fd41c4bbf 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -1,4 +1,62 @@ import Realm from "realm"; describe("Node.js Data Types", () => { -}) \ No newline at end of file + test("should work with Mixed Type", async () => { + // :code-block-start: define-mixed-in-schema + const DogSchema = { + name: "Dog", + properties: { + name: "string", + birthDate: "mixed", + }, + }; + // :code-block-end: + + const realm = await Realm.open({ + schema: [DogSchema], + }); + + // :code-block-start: create-objects-with-mixed-values + realm.write(() => { + // create a Dog with a birthDate value of type string + realm.create("Dog", { name: "Euler", birthDate: "December 25th, 2017" }); + + // create a Dog with a birthDate value of type date + realm.create("Dog", { + name: "Blaise", + birthDate: new Date("August 17, 2020"), + }); + // create a Dog with a birthDate value of type int + realm.create("Dog", { + name: "Euclid", + birthDate: 10152021, + }); + // create a Dog with a birthDate value of type null + realm.create("Dog", { + name: "Pythagoras", + birthDate: null, + }); + }); + // :code-block-end: + + // :code-block-start: query-objects-with-mixed-values + // query for Blaise's birthDate by filtering for his name to get the entire Realm object and using dot notation to get the birthDate + let blaiseBirthDate = realm.objects("Dog").filtered(`name = 'Blaise'`)[0] + .birthDate; + console.log(`Blaise's birth date is ${blaiseBirthDate}`); + // :code-block-end: + expect(blaiseBirthDate).toEqual(new Date("August 17, 2020")); + + // delete the objects specifically created in this test to keep tests idempotent + const Euler = realm.objects("Dog").filtered(`name = 'Euler'`)[0]; + 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]; + realm.write(() => { + realm.delete(Euler); + realm.delete(Blaise); + realm.delete(Euclid); + realm.delete(Pythagoras); + }); + }); +}); diff --git a/source/examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js b/source/examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js new file mode 100644 index 0000000000..ab8b0517f0 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js @@ -0,0 +1,20 @@ +realm.write(() => { + // create a Dog with a birthDate value of type string + realm.create("Dog", { name: "Euler", birthDate: "December 25th, 2017" }); + + // create a Dog with a birthDate value of type date + realm.create("Dog", { + name: "Blaise", + birthDate: new Date("August 17, 2020"), + }); + // create a Dog with a birthDate value of type int + realm.create("Dog", { + name: "Euclid", + birthDate: 10152021, + }); + // create a Dog with a birthDate value of type null + realm.create("Dog", { + name: "Pythagoras", + birthDate: null, + }); +}); diff --git a/source/examples/generated/node/data-types.codeblock.define-mixed-in-schema.js b/source/examples/generated/node/data-types.codeblock.define-mixed-in-schema.js new file mode 100644 index 0000000000..50f8ee7229 --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.define-mixed-in-schema.js @@ -0,0 +1,7 @@ +const DogSchema = { + name: "Dog", + properties: { + name: "string", + birthDate: "mixed", + }, +}; diff --git a/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js b/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js new file mode 100644 index 0000000000..b21e4dda8b --- /dev/null +++ b/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js @@ -0,0 +1,3 @@ +// query for Blaise's birthDate by filtering for his name to get the entire Realm object and using dot notation to get the birthDate +let blaiseBirthDate = realm.objects("Dog").filtered(`name = 'Blaise'`)[0].birthDate; +console.log(`Blaise's birth date is ${blaiseBirthDate}`); diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt index 06a5d9b3fa..68a39fcc58 100644 --- a/source/sdk/node/data-types/mixed.txt +++ b/source/sdk/node/data-types/mixed.txt @@ -14,4 +14,52 @@ Mixed - Node.js SDK .. versionadded:: 10.5.0-beta.1 Overview --------- \ No newline at end of file +-------- +The mixed data type is a {+realm+} property type can hold different data types. +Supported data types include: + +- bool +- int +- float +- double +- string +- Date +- Data +- UUID +- Set +- null + +.. note:: + + The mixed data type is indexable, but you can't use it as a primary key. + Because null is a permitted value, you can't declare a Mixed property as + optional. + +Realm Object Models +------------------- +To :ref:`define a property of your object model +` as mixed, set the property's type to +``"mixed"``. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.define-mixed-in-schema.js + :language: javascript + +Create an Object With a Mixed Value +----------------------------------- +Create an object with a mixed value by running the :js-sdk:`realm.create() +` method within a write transaction. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.create-objects-with-mixed-values.js + :language: javascript + +Query for Objects with a Mixed Value +------------------------------------ +Query for objects with a mixed value by running the +:js-sdk:`Collection.filtered() ` method and +passing in a :ref:`filter ` for a non-mixed field. You can +then print the value of the mixed property or the entire object itself. + +.. literalinclude:: /examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js + :language: javascript + + From 825a32625ecae9eac006d851ce4f35cdae124aaf Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Mon, 10 May 2021 08:19:38 -0400 Subject: [PATCH 7/9] fixed wording --- source/sdk/node/data-types/mixed.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/sdk/node/data-types/mixed.txt b/source/sdk/node/data-types/mixed.txt index 68a39fcc58..4b3e280228 100644 --- a/source/sdk/node/data-types/mixed.txt +++ b/source/sdk/node/data-types/mixed.txt @@ -15,7 +15,7 @@ Mixed - Node.js SDK Overview -------- -The mixed data type is a {+realm+} property type can hold different data types. +The mixed data type is a {+realm+} property type that can hold different data types. Supported data types include: - bool @@ -37,7 +37,7 @@ Supported data types include: Realm Object Models ------------------- -To :ref:`define a property of your object model +To :ref:`set a property of your object model ` as mixed, set the property's type to ``"mixed"``. From e9c17120998b7fe985235ae3c61da600ad0b4238 Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 11:22:42 -0400 Subject: [PATCH 8/9] Update source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js --- .../data-types.codeblock.query-objects-with-mixed-values.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js b/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js index b21e4dda8b..cd3ea34e2f 100644 --- a/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js +++ b/source/examples/generated/node/data-types.codeblock.query-objects-with-mixed-values.js @@ -1,3 +1,4 @@ -// query for Blaise's birthDate by filtering for his name to get the entire Realm object and using dot notation to get the birthDate +// To query for Blaise's birthDate, filter for his name to retrieve the realm object. +// Use dot notation to access the birthDate property. let blaiseBirthDate = realm.objects("Dog").filtered(`name = 'Blaise'`)[0].birthDate; console.log(`Blaise's birth date is ${blaiseBirthDate}`); From 5e75e84e5142246dd67e79b9f29e376e9b2dc8ac Mon Sep 17 00:00:00 2001 From: Mohammad Hunan Chughtai Date: Tue, 11 May 2021 11:22:47 -0400 Subject: [PATCH 9/9] Update examples/node/Examples/data-types.js --- examples/node/Examples/data-types.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/node/Examples/data-types.js b/examples/node/Examples/data-types.js index 4fd41c4bbf..ab3803d9a7 100644 --- a/examples/node/Examples/data-types.js +++ b/examples/node/Examples/data-types.js @@ -40,7 +40,8 @@ describe("Node.js Data Types", () => { // :code-block-end: // :code-block-start: query-objects-with-mixed-values - // query for Blaise's birthDate by filtering for his name to get the entire Realm object and using dot notation to get the birthDate + // To query for Blaise's birthDate, filter for his name to retrieve the realm object. + // Use dot notation to access the birthDate property. let blaiseBirthDate = realm.objects("Dog").filtered(`name = 'Blaise'`)[0] .birthDate; console.log(`Blaise's birth date is ${blaiseBirthDate}`);