From a3f8cad28f6a0a510ce93feb48ecb09d1ec710a6 Mon Sep 17 00:00:00 2001 From: norareidy Date: Wed, 8 May 2024 13:59:09 -0400 Subject: [PATCH 1/2] DOCSP-38823: Insert docs with geospatial data --- .../fundamentals/crud/read-operations/geo.txt | 35 +++++++++++++++++++ .../fundamentals/code-snippets/Geo.java | 24 +++++++++++++ 2 files changed, 59 insertions(+) diff --git a/source/fundamentals/crud/read-operations/geo.txt b/source/fundamentals/crud/read-operations/geo.txt index a0f5f400e..9c0533b12 100644 --- a/source/fundamentals/crud/read-operations/geo.txt +++ b/source/fundamentals/crud/read-operations/geo.txt @@ -85,6 +85,23 @@ To learn more about the shapes you can use in MongoDB, see the .. external resource +Insert a Document Containing GeoJSON Data +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To insert a document that stores GeoJSON data, specify a document that contains a GeoJSON +value and pass the document to the ``insertOne()`` method. + +The following example inserts a document that includes a ``location.geo`` field, +which stores GeoJSON data: + +.. literalinclude:: /includes/fundamentals/code-snippets/Geo.java + :language: java + :dedent: + :start-after: begin insertGeoJSONExample + :end-before: end insertGeoJSONExample + +To learn more about inserting documents, see the :ref:`java-fundamentals-insert` guide. + Index ~~~~~ @@ -118,6 +135,24 @@ Legacy coordinate pairs have the following structure: Your field should contain an array of two values in which the first represents the ``x`` axis value and the second represents the ``y`` axis value. +Insert a Document Containing Legacy Coordinates +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +To insert a document that stores a legacy coordinate pair, create a document that +assigns a coordinate pair value to a field. Then, pass the document to the +``insertOne()`` method. + +The following example inserts a document that includes a ``coordinates`` field, +which stores geospatial data as a legacy coordinate pair: + +.. literalinclude:: /includes/fundamentals/code-snippets/Geo.java + :language: java + :dedent: + :start-after: begin insertLegacyExample + :end-before: end insertLegacyExample + +To learn more about inserting documents, see the :ref:`java-fundamentals-insert` guide. + Index ~~~~~ diff --git a/source/includes/fundamentals/code-snippets/Geo.java b/source/includes/fundamentals/code-snippets/Geo.java index 8ac60c433..3e11a2d46 100644 --- a/source/includes/fundamentals/code-snippets/Geo.java +++ b/source/includes/fundamentals/code-snippets/Geo.java @@ -43,6 +43,30 @@ public void go() { } + private void insertGeoJSONExample() { + // begin insertGeoJSONExample + + // Add your MongoCollection setup code here + Point point = new Point(new Position(-74.0065, 40.7085)); + + Document theater = new Document("theaterId", 1203) + .append("location", new Document("geo", point)); + + InsertOneResult result = collection.insertOne(theater); + // end insertGeoJSONExample + } + + private void insertLegacyExample() { + // begin insertLegacyExample + + // Add your MongoCollection setup code here + Document theater = new Document("theaterId", 1204) + .append("coordinates", Arrays.asList(-73.9862, 40.7311)); + + InsertOneResult result = collection.insertOne(theater); + // end insertLegacyExample + } + private void nearExample() { // begin findExample From 296701fda7bc040caf8f232344fa5d2d1d26c615 Mon Sep 17 00:00:00 2001 From: norareidy Date: Thu, 9 May 2024 10:15:03 -0400 Subject: [PATCH 2/2] MW feedback --- source/fundamentals/crud/read-operations/geo.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/fundamentals/crud/read-operations/geo.txt b/source/fundamentals/crud/read-operations/geo.txt index 9c0533b12..2075b79df 100644 --- a/source/fundamentals/crud/read-operations/geo.txt +++ b/source/fundamentals/crud/read-operations/geo.txt @@ -88,11 +88,11 @@ To learn more about the shapes you can use in MongoDB, see the Insert a Document Containing GeoJSON Data ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -To insert a document that stores GeoJSON data, specify a document that contains a GeoJSON +To insert a document that stores GeoJSON data, create a document that contains a GeoJSON value and pass the document to the ``insertOne()`` method. The following example inserts a document that includes a ``location.geo`` field, -which stores GeoJSON data: +which contains GeoJSON data: .. literalinclude:: /includes/fundamentals/code-snippets/Geo.java :language: java @@ -143,7 +143,7 @@ assigns a coordinate pair value to a field. Then, pass the document to the ``insertOne()`` method. The following example inserts a document that includes a ``coordinates`` field, -which stores geospatial data as a legacy coordinate pair: +which contains a legacy coordinate pair: .. literalinclude:: /includes/fundamentals/code-snippets/Geo.java :language: java