Skip to content

Commit d1ae4c7

Browse files
caitlindaveyCaitlin Davey
andauthored
Docsp 26803 adding wildcard code example (#405)
* DOCSP-22622 Changed default visibility for code blocs so they are hidden * DOCSP-26803 - Add wildcard code example. * autobuilder --------- Co-authored-by: Caitlin Davey <[email protected]>
1 parent 8cc88c4 commit d1ae4c7

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

source/fundamentals/indexes.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,25 @@ For more information, see the :manual:`Unique Indexes</core/index-unique>` page
396396

397397
.. driver-content-end
398398

399+
Wildcard Indexes
400+
~~~~~~~~~~~~~~~~
401+
402+
.. _wildcard-indexes:
403+
404+
Wildcard indexes enable queries against unknown or arbitrary fields.
405+
These indexes can be beneficial if you are using a dynamic schema.
406+
407+
The following example creates an ascending wildcard index on all
408+
values of the ``location`` field, including values nested in subdocuments and arrays:
409+
410+
.. literalinclude:: /includes/fundamentals/code-snippets/IndexPage.java
411+
:language: java
412+
:dedent:
413+
:start-after: begin wildcard index
414+
:end-before: end wildcard index
415+
416+
For more information, see the :manual:`Wildcard Indexes</core/index-wildcard>` page in the {+mdb-server+} manual.
417+
399418
.. _java-clustered-indexes:
400419

401420
Clustered Indexes

source/includes/fundamentals/code-snippets/IndexPage.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,4 +156,13 @@ private void uniqueIndex() {
156156
}
157157
// end unique index
158158
}
159+
private void wildcardIndex() {
160+
System.out.println("wildcard index");
161+
collection = database.getCollection("theaters");
162+
163+
// begin wildcard index
164+
String resultCreateIndex = collection.createIndex(Indexes.ascending("location.$**"));
165+
System.out.println(String.format("Index created: %s", resultCreateIndex));
166+
// end wildcard index
167+
}
159168
}

0 commit comments

Comments
 (0)