-
Notifications
You must be signed in to change notification settings - Fork 17
DOCSP-39685: Indexes landing page #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c8c26ed
DOCSP-39685: Indexes landing page
mcmorisi 7c6ad5a
Fix
mcmorisi eda99fe
Address NR feedback
mcmorisi dbc0dd9
Address technical feedback
mcmorisi 6699013
Fix
mcmorisi f89382b
fix
mcmorisi 90d0245
Fix
mcmorisi 638a476
Fix
mcmorisi 4a07841
Address further technical feedback
mcmorisi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
117 changes: 117 additions & 0 deletions
117
source/includes/usage-examples/index-code-examples.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
import com.mongodb.ConnectionString; | ||
import com.mongodb.MongoClientSettings; | ||
import com.mongodb.ServerApi; | ||
import com.mongodb.ServerApiVersion; | ||
|
||
import com.mongodb.client.model.ClusteredIndexOptions; | ||
import com.mongodb.client.model.CreateCollectionOptions; | ||
import com.mongodb.client.model.IndexOptions; | ||
import com.mongodb.client.model.Indexes; | ||
import com.mongodb.reactivestreams.client.*; | ||
import org.bson.Document; | ||
import org.reactivestreams.Publisher; | ||
import reactor.core.publisher.Flux; | ||
import reactor.core.publisher.Mono; | ||
|
||
public class IndexExamples { | ||
public static void main(String[] args) { | ||
// Replace the placeholder with your Atlas connection string | ||
String uri = "<connection string URI>"; | ||
|
||
// Construct a ServerApi instance using the ServerApi.builder() method | ||
ServerApi serverApi = ServerApi.builder() | ||
.version(ServerApiVersion.V1) | ||
.build(); | ||
|
||
MongoClientSettings settings = MongoClientSettings.builder() | ||
.applyConnectionString(new ConnectionString(uri)) | ||
.serverApi(serverApi) | ||
.build(); | ||
|
||
// Create a new client and connect to the server | ||
try (MongoClient mongoClient = MongoClients.create(settings)) { | ||
MongoDatabase database = mongoClient.getDatabase("sample_mflix"); | ||
MongoCollection<Document> collection = database.getCollection("movies"); | ||
|
||
// start-single-field | ||
Publisher<String> publisher = collection.createIndex(Indexes.ascending("<field name>")); | ||
Mono.from(publisher).block(); | ||
// end-single-field | ||
|
||
// start-compound | ||
Publisher<String> publisher = collection.createIndex(Indexes.ascending("<field name 1>", "<field name 2>")); | ||
Mono.from(publisher).block(); | ||
// end-compound | ||
|
||
// start-multikey | ||
Publisher<String> publisher = collection.createIndex(Indexes.ascending("<array field name>")); | ||
Mono.from(publisher).block(); | ||
// end-multikey | ||
|
||
// start-search-create | ||
Document index = new Document("mappings", new Document("dynamic", true)); | ||
Publisher<String> publisher = collection.createSearchIndex("<index name>", index); | ||
Mono.from(publisher).block(); | ||
// end-search-create | ||
|
||
// start-search-list | ||
ListSearchIndexesPublisher<Document> listIndexesPublisher = collection.listSearchIndexes(); | ||
|
||
Flux.from(listIndexesPublisher) | ||
.doOnNext(System.out::println) | ||
.blockLast(); | ||
// end-search-list | ||
|
||
// start-search-update | ||
Document newIndex = new Document("mappings", new Document("dynamic", true)); | ||
Publisher<Void> publisher = collection.updateSearchIndex("<index name>", newIndex); | ||
Mono.from(publisher).block(); | ||
// end-search-update | ||
|
||
// start-search-delete | ||
Publisher<Void> publisher = collection.dropIndex("<index name>"); | ||
Mono.from(publisher).block(); | ||
// end-search-delete | ||
|
||
// start-text | ||
Publisher<String> publisher = collection.createIndex(Indexes.text("<field name>")); | ||
Mono.from(publisher).block(); | ||
// end-text | ||
|
||
// start-geo | ||
Publisher<String> publisher = collection.createIndex(Indexes.geo2dsphere("<GeoJSON object field>")); | ||
Mono.from(publisher).block(); | ||
// end-geo | ||
|
||
// start-unique | ||
IndexOptions indexOptions = new IndexOptions().unique(true); | ||
Publisher<String> publisher = collection.createIndex(Indexes.ascending("<field name>"), indexOptions); | ||
Mono.from(publisher).block(); | ||
// end-unique | ||
|
||
// start-wildcard | ||
Publisher<String> publisher = collection.createIndex(Indexes.ascending("$**")); | ||
Mono.from(publisher).block(); | ||
// end-wildcard | ||
|
||
// start-clustered | ||
ClusteredIndexOptions clusteredIndexOptions = new ClusteredIndexOptions( | ||
Indexes.ascending("_id"), | ||
true | ||
); | ||
|
||
CreateCollectionOptions createCollectionOptions= new CreateCollectionOptions() | ||
.clusteredIndexOptions(clusteredIndexOptions); | ||
|
||
Publisher<Void> clusteredCollection = database.createCollection("<collection name>", | ||
createCollectionOptions); | ||
Mono.from(clusteredCollection).block(); | ||
// end-clustered | ||
|
||
// start-remove | ||
Publisher<Void> publisher = collection.dropIndex("<index name>"); | ||
Mono.from(publisher).block(); | ||
// end-remove | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
You can use the following sample application to test the code examples on this | ||
page. To use the sample application, perform the following steps: | ||
|
||
1. Create a new Java project in your IDE. | ||
#. Install the {+driver-short+} in your Java project. | ||
#. Install the `Project Reactor library | ||
<https://projectreactor.io/docs/core/release/reference/#getting>`__ in your | ||
Java project. | ||
#. Copy the following code and paste it into a new Java file named ``IndexApp.java``. | ||
#. Copy a code example from this page and paste it on the specified lines in the | ||
file. |
41 changes: 41 additions & 0 deletions
41
source/includes/usage-examples/sample-index-application.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import com.mongodb.ConnectionString; | ||
import com.mongodb.MongoClientSettings; | ||
import com.mongodb.ServerApi; | ||
import com.mongodb.ServerApiVersion; | ||
|
||
import com.mongodb.client.model.ClusteredIndexOptions; | ||
import com.mongodb.client.model.CreateCollectionOptions; | ||
import com.mongodb.client.model.IndexOptions; | ||
import com.mongodb.client.model.Indexes; | ||
import com.mongodb.reactivestreams.client.*; | ||
import org.bson.Document; | ||
import org.reactivestreams.Publisher; | ||
import reactor.core.publisher.Flux; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The imports here must be the same as in |
||
import reactor.core.publisher.Mono; | ||
|
||
public class IndexApp { | ||
public static void main(String[] args) { | ||
// Replace the placeholder with your Atlas connection string | ||
String uri = "<connection string URI>"; | ||
|
||
// Construct a ServerApi instance using the ServerApi.builder() method | ||
ServerApi serverApi = ServerApi.builder() | ||
.version(ServerApiVersion.V1) | ||
.build(); | ||
|
||
MongoClientSettings settings = MongoClientSettings.builder() | ||
.applyConnectionString(new ConnectionString(uri)) | ||
.serverApi(serverApi) | ||
.build(); | ||
|
||
// Create a new client and connect to the server | ||
try (MongoClient mongoClient = MongoClients.create(settings)) { | ||
MongoDatabase database = mongoClient.getDatabase("<database name>"); | ||
MongoCollection<Document> collection = database.getCollection("<collection name>"); | ||
|
||
// Start example code here | ||
|
||
// End example code here | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems out of place, given other examples in the documentation don't provide such information. Generally, they seem to provide a block about the examples using Project reactor.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can add the extra info about using Project reactor to be more in line with the Read/Write landing pages.