Skip to content

Docsp 26803 adding wildcard code example #405

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions source/fundamentals/indexes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,25 @@ For more information, see the :manual:`Unique Indexes</core/index-unique>` page

.. driver-content-end

Wildcard Indexes
~~~~~~~~~~~~~~~~

.. _wildcard-indexes:

Wildcard indexes enable queries against unknown or arbitrary fields.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

  1. I think it would be good to avoid passive voice unless it makes it sound like you are blaming the user (style guide). I see that this sentence is verbatim from the Server Manual page, but I think that wasn't a particularly good sentence (and given the 4.2 release note, it was probably written ~5-6 years ago prior to authoring or adopting the style guide).

  2. Avoid I think "arbitrary" usually carries a negative connotation and that it is not that accurate. The fields actually need to follow the pattern that you define (whether the pattern is all fields, nested fields, or multiple specific fields.

Suggested change
Wildcard indexes enable queries against unknown or arbitrary fields.
You can use wildcard indexes to instruct MongoDB to index all field names that match a pattern.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't passive voice...?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks for the correction!

These indexes can be beneficial if you are using a dynamic schema.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

  1. I think it would be good to avoid passive voice, per the style guide.

  2. I know the Server Manual mentions "dynamic schemas", but that is jargon that I think could be avoided or explained.

Suggested change
These indexes can be beneficial if you are using a dynamic schema.
You can use these indexes when you need to match a set of fields based on the field names, specific subdocuments or arrays, and where they are located in the document schema.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also not passive voice

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, thanks for the correction!


The following example creates an ascending wildcard index on all
values of the ``location`` field, including values nested in subdocuments and arrays:
Comment on lines +407 to +408
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue:

I could be wrong, but I think the terminology is usually used when creating an index is to specify that it is on the field rather than the value. For example, see the headings on the createIndex Server Manual page. Each of the headings mentions "Create an Index on... Field". The action MongoDB takes is to index the values for the fields.

Suggestion:

Suggested change
The following example creates an ascending wildcard index on all
values of the ``location`` field, including values nested in subdocuments and arrays:
The following code example shows how you can create an ascending
wildcard index to instruct MongoDB to index values of the \`\`location\`\`
field, and all values nested in subdocuments and arrays:


.. literalinclude:: /includes/fundamentals/code-snippets/IndexPage.java
:language: java
:dedent:
:start-after: begin wildcard index
:end-before: end wildcard index

For more information, see the :manual:`Wildcard Indexes</core/index-wildcard>` page in the {+mdb-server+} manual.

.. _java-clustered-indexes:

Clustered Indexes
Expand Down
9 changes: 9 additions & 0 deletions source/includes/fundamentals/code-snippets/IndexPage.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,13 @@ private void uniqueIndex() {
}
// end unique index
}
private void wildcardIndex() {
System.out.println("wildcard index");
collection = database.getCollection("theaters");

// begin wildcard index
String resultCreateIndex = collection.createIndex(Indexes.ascending("location.$**"));
System.out.println(String.format("Index created: %s", resultCreateIndex));
// end wildcard index
}
}