Skip to content

Commit 7e6600a

Browse files
committed
fixes
1 parent 246c099 commit 7e6600a

File tree

2 files changed

+28
-26
lines changed

2 files changed

+28
-26
lines changed

source/atlas-search.txt

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,20 @@ In this guide, you can learn how to use the **Atlas Search** feature on a collec
2525
Atlas Search enables you to perform full-text searches on collections hosted on MongoDB
2626
Atlas. Atlas Search indexes specify the behavior of the search and which fields to index.
2727

28+
Sample Data
29+
~~~~~~~~~~~
30+
31+
The example in this guide uses the ``movies`` collection in the ``sample_mflix``
32+
database from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to
33+
create a free MongoDB Atlas cluster and load the sample datasets, see the
34+
:atlas:`Get Started with Atlas </getting-started>` guide.
35+
2836
Run an Atlas Search Query
2937
-------------------------
3038

3139
This section shows how to create an aggregation pipeline to run an
32-
Atlas Search on a collection. You can use ``Aggregates.search`` builder to
33-
create a ``$search`` pipeline stage and specify your search. Then, call
40+
Atlas Search on a collection. You can use the ``Aggregates.search()`` builder
41+
method to create a ``$search`` pipeline stage and specify your search. Then, call
3442
the ``aggregate()`` method and pass your pipeline as a parameter.
3543

3644
.. tip::
@@ -42,23 +50,16 @@ Before running an Atlas Search query, you must create an Atlas Search index
4250
on your collection. To learn how to programmatically create an Atlas Search
4351
index, see the :ref:`java-search-indexes` section in the Indexes guide.
4452

45-
Sample Data
46-
~~~~~~~~~~~
47-
48-
The example in this section uses the ``movies`` collection in the ``sample_mflix``
49-
database from the :atlas:`Atlas sample datasets </sample-data>`. To learn how to
50-
create a free MongoDB Atlas cluster and load the sample datasets, see the
51-
:atlas:`Get Started with Atlas </getting-started>` guide.
52-
5353
Atlas Search Example
5454
~~~~~~~~~~~~~~~~~~~~
5555

5656
This example performs an Atlas Search query by calling the
57-
``aggregate()`` method and passing the following pipeline stages:
57+
``aggregate()`` method and passing the following pipeline stage
58+
builders:
5859

59-
- ``Aggregates.search``: Specifies a search query for documents in which
60+
- ``Aggregates.search()``: Specifies a search query for documents in which
6061
the ``title`` field contains the word ``"Alabama"``
61-
- ``Aggregates.project``: Projects the ``title`` field of each matching document
62+
- ``Aggregates.project()``: Projects the ``title`` field of each matching document
6263

6364
.. io-code-block::
6465
:copyable:
@@ -92,9 +93,9 @@ in the Atlas documentation.
9293
API Documentation
9394
~~~~~~~~~~~~~~~~~
9495

95-
To learn more about the methods and pipeline stages mentioned in this guide, see
96+
To learn more about the methods mentioned in this guide, see
9697
the following API documentation:
9798

9899
- `MongoCollection.aggregate() <{+api+}/apidocs/mongodb-driver-sync/com/mongodb/client/MongoCollection.html#aggregate(java.util.List)>`__
99-
- `Aggregates.search <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#search(com.mongodb.client.model.search.SearchCollector)>`__
100-
- `Aggregates.project <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#project(org.bson.conversions.Bson)>`__
100+
- `Aggregates.search() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#search(com.mongodb.client.model.search.SearchCollector)>`__
101+
- `Aggregates.project() <{+api+}/apidocs/mongodb-driver-core/com/mongodb/client/model/Aggregates.html#project(org.bson.conversions.Bson)>`__

source/includes/AtlasSearch.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Creates and uses Atlas Search indexes by using the Java driver
1+
// Runs an Atlas Search query by using the Java driver
22

33
package org.example;
44

@@ -15,22 +15,23 @@
1515

1616
public class AtlasSearch {
1717
public static void main(String[] args) {
18-
String uri = "<connection-string>";
18+
String uri = "<connection string>";
1919

2020
try (MongoClient mongoClient = MongoClients.create(uri)) {
2121
MongoDatabase database = mongoClient.getDatabase("sample_mflix");
2222
MongoCollection<Document> collection = database.getCollection("movies");
2323

24+
// Queries for documents that have a "title" value containing the word "Alabama"
2425
// begin-atlas-search
25-
collection.aggregate(
26-
Arrays.asList(
27-
Aggregates.search(SearchOperator.text(
28-
SearchPath.fieldPath("title"), "Alabama")),
29-
Aggregates.project(Projections.include("title"))
30-
)
31-
).forEach(doc -> System.out.println(doc.toJson()));
26+
collection.aggregate(
27+
Arrays.asList(
28+
Aggregates.search(SearchOperator.text(
29+
SearchPath.fieldPath("title"), "Alabama")),
30+
Aggregates.project(Projections.include("title"))
31+
)
32+
).forEach(doc -> System.out.println(doc.toJson()));
3233
// end-atlas-search
33-
34+
3435
}
3536
}
3637
}

0 commit comments

Comments
 (0)