You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* docs: fix broken xrefs in quicktour and kotlin pages
* docs: fix xref target from indexing to references in quicktour
* docs: fix incorrect API usage in quicktour and updates examples
* docs: fix textSearches examples - stale path, malformed save, removed execute()
* docs: fix invalid AsciiDoc syntax - [WARN] admonition and Markdown fences
* docs: fix typos and self-contradiction in configuration page
* docs: complete references page - add MorphiaReference section and fix spacing
* docs: add deprecation notice to updating-old and link from nav
* docs: normalize all page titles to level-1 headings
* docs: rename camelCase page files to kebab-case
* docs: replace MapperOptions with MorphiaConfig and fix prose in mapping page
* docs: update stale 2.x test file paths to 3.0 core/ layout
* docs: use {srcRef} for test link in life-cycle-methods
* docs: fix typos across sharding, schema-validation, life-cycle-methods, migrating, indexing, quicktour
* docs: mark included files as page-partial, fix Update Operators caption
* touch up the docs
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/aggregations.adoc
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,11 +1,11 @@
1
-
==Aggregations
1
+
= Aggregations
2
2
3
3
The {docsRef}/aggregation[aggregation framework] in MongoDB allows you to define a series (called a pipeline) of operations (called stages) against the data in a collection.
4
4
These pipelines can be used for analytics or they can be used to convert your data from one form to another.
5
5
This guide will not go in to the details of how aggregation works, however.
6
6
The official MongoDB {docsRef}/aggregation[documentation] has extensive tutorials on such details.
7
7
Rather, this guide will focus on the Morphia API. The examples shown here are taken from the
8
-
{srcRef}/morphia/src/test/java/dev/morphia/aggregation/AggregationTest.java[tests] in Morphia itself. You can find the full list in the <<Supported Operators>> section.
8
+
{srcRef}/core/src/test/java/dev/morphia/aggregation/AggregationTest.java[tests] in Morphia itself. You can find the full list in the <<Supported Operators>> section.
9
9
10
10
Writing an aggregation pipeline starts just like writing a standard query.
`aggregate()` takes a `Class` literal. This lets Morphia know which collection to perform this aggregation against. Because of the transformational operations available in the aggregation {docsRef}/core/aggregation-pipeline[pipeline], Morphia can not validate as much as it can with querying so care will need to be taken to ensure document fields actually exist when referencing them in your pipeline.
19
19
20
-
===The Pipeline
20
+
== The Pipeline
21
21
22
22
Aggregation pipelines are comprised of a series stages.
23
23
Our example here with the `group()` stage. This method is the Morphia equivalent of the
@@ -34,7 +34,7 @@ the Morphia equivalent of an {docsRef}/reference/operator/aggregation/group/#gro
Once your pipeline is complete, you can execute it via the `execute()` method.
40
40
This method optionally takes a `Class` reference for the target type of your aggregation.
@@ -43,7 +43,7 @@ Additionally, you can also include some options to `execute()`.
43
43
We can use the various options on the
44
44
link:javadoc/dev/morphia/aggregation/AggregationOptions.html[AggregationOptions] class to configure how we want the pipeline to execute.
45
45
46
-
==== $out
46
+
== $out
47
47
48
48
Depending your use case, you might not want to return the results of your aggregation but simply output them to another collection.
49
49
That's where `$out` comes in. {docsRef}/reference/operator/aggregation/out/[$out] is an operator that allows the results of a pipeline to be stored in to a named collection.
@@ -66,7 +66,7 @@ that reflects the collection we want to write our output to. Morphia will use t
66
66
your entities to determine that collection name. You may also pass a String with the collection name as well if the target collection
67
67
does not correspond to a mapped entity.
68
68
69
-
==== $merge
69
+
== $merge
70
70
71
71
{docsRef}/reference/operator/aggregation/merge/[$merge] is a very similar option with a some major differences.
72
72
The biggest difference is that `$merge` can write to existing collections without destroying the existing documents. `$out` would
@@ -86,7 +86,7 @@ Because there may be existing data in the collection, we need to instruct the op
86
86
In this example, when documents matching we're choosing to replace them and when they don't we're instructing the operation to insert the
87
87
new documents in to the collection. Other options are defined on `com.mongodb.client.model.MergeOptions` type defined by the Java driver.
88
88
89
-
=== Supported Operators
89
+
== Supported Operators
90
90
Every effort is made to provide 100% coverage of all the operators offered by MongoDB. A select handful of operators have been excluded
91
91
for reasons of suitability in Morphia. In short, some operators just don't make sense in Morphia. Below is listed all the currently
92
92
supported operators. To see an example of an operator in action, click through to see the test cases for that operator.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/configuration.adoc
+22-24Lines changed: 22 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,28 +1,28 @@
1
-
==Configuration
1
+
= Configuration
2
2
3
-
Starting in Morphia 3.0, configuration will be driven via a configuration file. However programmatic configuration is still supportedfor those who prefer, or need, a more flexible approach. The file should live in your build's resources folder and be named `META-INF/morphia-config.properties`. Reference documentation for the configuration file can be found in the link:++javadoc/dev/morphia/config/MorphiaConfig.html++[javadoc] but
3
+
Starting in Morphia 3.0, configuration will be driven via a configuration file. However programmatic configuration is still supported for those who prefer, or need, a more flexible approach. The file should live in your build's resources folder and be named `META-INF/morphia-config.properties`. Reference documentation for the configuration file can be found in the link:++javadoc/dev/morphia/config/MorphiaConfig.html++[javadoc] but
4
4
we'll go in depth on a few items here. An example configuration file is included below. All possible configuration elements are listed. However, if the default values are acceptable that element can be safely omitted from your file.
5
5
6
6
`Morphia.createDatastore()` can be called link:++javadoc/dev/morphia/Morphia.html#createDatastore(com.mongodb.client.MongoClient,dev.morphia.config.MorphiaConfig)++[with]
7
7
and link:++javadoc/dev/morphia/Morphia.html#createDatastore(com.mongodb.client.MongoClient)++[without] an explicit `MorphiaConfig`
8
-
argument. When not explicitly given a `MorphiaConfig`, Morphia will attempt to load the configuration file at the location show above.
8
+
argument. When not explicitly given a `MorphiaConfig`, Morphia will attempt to load the configuration file at the location shown above.
9
9
Failing to find a configuration file, it will create a new configuration using the default values which can be found in the javadoc.
10
10
These values are unlikely to be suitable long term but should be sufficient for newcomers looking to test things out a little before
11
11
committing to adopt Morphia.
12
12
13
-
===Manually loading configurations
13
+
== Manually loading configurations
14
14
In some cases, you might find the need for multiple configuration files. Such scenarios include varying test
15
15
environments/configurations, multiple dataset configurations, or externally supplied configurations. In such cases, you can manually
16
16
load those configurations using link:++javadoc/dev/morphia/config/MorphiaConfig.html#load(java.lang.String)++[MorphiaConfig.load()]. You
17
17
can then pass this instance to `createDatastore()`.
18
18
19
-
=== Dynamic configuration creation
19
+
== Dynamic configuration creation
20
20
For many, the ability to dynamically create `MorphiaConfig` instances is not just a nicety but a hard requirement. In this case, there
21
21
are methods on `MorphiaConfig` to return a new version of the configuration with the updated value. `MorphiaConfig` is immutable,
22
22
however, so be sure to use the returned reference and not the original. It should also be noted that once a `Datastore` is created using
23
23
a `MorphiaConfig`, that configuration is fixed and can not be changed. A new `Datastore` would need to be created with the updated version.
24
24
25
-
=== Collection and property naming
25
+
== Collection and property naming
26
26
27
27
* `morphia.collection-naming`
28
28
* `morphia.property-naming`
@@ -50,7 +50,7 @@ For the provided strategies, you can simply use the shortened version as shown i
50
50
can enable it by giving the fully qualified classname (fqcn) instead. The same applies everywhere you see `fqcn` in the sample file.
51
51
====
52
52
53
-
=== Discriminator keys and values
53
+
== Discriminator keys and values
54
54
55
55
* `morphia.discriminator`
56
56
* `morphia.discriminator-key`
@@ -66,18 +66,19 @@ The choices here are simpler:
66
66
1. `className()`/`lowerClassName()`
67
67
2. `simpleName()`/`lowerSimpleName()`
68
68
69
-
Simple name is the fully qualified classname without the package name. These can all be accessed via their named methods on
69
+
Simple name is the class name without the package name. These can all be accessed via their named methods on
70
70
link:++javadoc/dev/morphia/mapping/DiscriminatorFunction.html++[DiscriminatorFunction] and just like the `NamingStrategy` cases, if the
71
71
provided options are not sufficient, you can implement your own by subclassing `DiscriminatorFunction` and implementing your own function.
72
72
73
-
=== Mapper selection
73
+
== Mapper selection
74
74
75
75
* `morphia.mapper`
76
76
77
77
Morphia supports two mapper implementations, selectable via configuration:
78
78
79
79
1. `reflection` *(default)* — the traditional reflection-based mapper. No additional dependencies required.
80
-
2. `critter` — a bytecode-generation mapper that produces `VarHandle`-based accessors at runtime via Gizmo, with automatic fallback to reflection if generation fails for a given type. Pre-generated models from the `critter-maven` plugin are used when available (AOT path), otherwise models are generated at JVM startup.
80
+
2. `critter` — a bytecode-generation mapper that produces bytecode to handle serialization rather than using reflection.
81
+
This option should give you better performance overall. Pre-generated models from the `critter-maven` plugin are used when available (AOT path), otherwise models are generated at JVM startup.
81
82
82
83
To enable the critter mapper, add the following to your `META-INF/morphia-config.properties`:
83
84
@@ -90,7 +91,7 @@ Or pass `-Dmorphia.mapper=critter` on the Maven command line when running tests.
90
91
91
92
For production deployments, consider using the xref:maven-plugin.adoc[critter-maven plugin] to generate models at build time and eliminate the startup cost entirely.
92
93
93
-
=== User-defined Codecs
94
+
== User-defined Codecs
94
95
95
96
* `morphia.codec-provider`
96
97
@@ -114,13 +115,13 @@ will not only make it consistent with other configurable elements but will make
114
115
the note below about using the ServiceLoader with Java 9 modules.
115
116
====
116
117
117
-
==== Property Codecs
118
+
== Property Codecs
118
119
As unusual as is the need for a custom codec to handle types, there are rare cases where how Morphia processes a property on entity needs
119
120
to be customized. This processing is handled via the
120
121
link:++javadoc/dev/morphia/mapping/codec/MorphiaPropertyCodecProvider.html++[MorphiaPropertyCodecProvider]. Morphia discovers these
121
122
custom implementations via SPI the details of which won't be covered here.
122
123
123
-
=== Legacy Configuration
124
+
== Legacy Configuration
124
125
125
126
Morphia can be configured in one of two ways: the legacy mode and the modern mode. The defaults in the configuration code will give you
126
127
the modern configuration and is the recommended way to configure Morphia. However, if you're upgrading an older project, you very likely
@@ -131,16 +132,14 @@ Using the legacy configuration is a matter of defining a few entries in your con
131
132
you already have a `MorphiaConfig` in hand but would like to update it to reflect the legacy style configuration, you can call `.legacy()`
132
133
on that reference and use the resulting `MorphiaConfig` instance.
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/indexing.adoc
+8-8Lines changed: 8 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
==Indexing
1
+
= Indexing
2
2
3
3
Morphia provides annotations that allow developers to define indexes for a collection to be defined alongside the other mapping data on an entity's source.
4
4
In addition to the familiar ascending/descending index types, Morphia and MongoDB support
@@ -10,7 +10,7 @@ setting the `morphia.apply-indexes` to true in the xref:configuration.adoc[confi
10
10
11
11
There are two ways to define indexes: at the class level and at the field level.
12
12
13
-
===Class Level Indexes
13
+
== Class Level Indexes
14
14
15
15
Class level indexing begins with the link:javadoc/dev/morphia/annotations/Indexes.html[@Indexes] annotation.
16
16
This is a container annotation whose sole purpose is to hold a number of link:javadoc/dev/morphia/annotations/Index.html[@Index] annotations.
@@ -38,7 +38,7 @@ public class IndexExample {
38
38
}
39
39
----
40
40
41
-
=== Fields
41
+
== Fields
42
42
43
43
Which fields to index are defined with the link:javadoc/dev/morphia/annotations/Field.html[@Field] annotation.
44
44
An arbitrary number of link:javadoc/dev/morphia/annotations/Field.html[@Field]s can be given but at least one must be present.
@@ -48,23 +48,23 @@ annotations.
48
48
For most index types, this value is validated by default.
49
49
An exception is made for <<_text_indexing,text indexing>> as discussed below.
50
50
51
-
=== Index Options
51
+
== Index Options
52
52
53
53
Options for an index are defined on the link:javadoc/dev/morphia/annotations/IndexOptions.html[@IndexOptions].
54
-
More complete documenation can be found in the {docsRef}/reference/method/db.collection.createIndex/#options[manual].
54
+
More complete documentation can be found in the {docsRef}/reference/method/db.collection.createIndex/#options[manual].
55
55
Using the options allows you to run indexing in the background, e.g. By default, creating an index blocks all other operations on a database.
56
56
When building an index on a collection, the database that holds the collection is unavailable for read or write operations until the index build completes.
57
57
For potentially long running index building operations, consider the **background** operation so that the MongoDB database remains available during the index building operation.
58
58
The MongoDB {docsRef}/core/index-creation/#background-construction[manual] has more detail.
59
59
60
-
By default Morphia will attempt to validate the fields specified but in some cases that isn't desirable so you can turn it off via the options refernce. `IndexOptions` lets you define {docsRef}/core/index-ttl/[TTL], {docsRef}/core/index-sparse/[sparse], and {docsRef}/core/index-partial/[partial] indexes as well. `IndexOptions` can also be used to give an index a more human friendly name.
60
+
By default Morphia will attempt to validate the fields specified but in some cases that isn't desirable so you can turn it off via the options reference. `IndexOptions` lets you define {docsRef}/core/index-ttl/[TTL], {docsRef}/core/index-sparse/[sparse], and {docsRef}/core/index-partial/[partial] indexes as well. `IndexOptions` can also be used to give an index a more human friendly name.
61
61
62
62
[NOTE]
63
63
====
64
64
Whether user specified or MongoDB generated, index names including their full namespace (i.e. database.collection) cannot be longer than the {docsRef}/reference/limits/#Index-Name-Length[Index Name Limit].
65
65
====
66
66
67
-
==== Partial Indexes
67
+
== Partial Indexes
68
68
69
69
New in MongoDB 3.2, https://docs.mongodb.com/v3.2/core/index-partial/[partial indexes] only index the documents in a collection that meet a specified filter expression thereby reducing storage and maintenance costs.
70
70
A partial filter is defined using a query as shown here:
@@ -122,7 +122,7 @@ A wild card text index declaration would look like this:
122
122
A collection can have at most one text index.
123
123
====
124
124
125
-
=== Collation
125
+
== Collation
126
126
127
127
Collation allows users to specify language-specific rules for string comparison such as rules for lettercase and accent marks.
128
128
A collation can be defined using the `collation()` property on link:javadoc/dev/morphia/annotations/IndexOptions.html[@IndexOptions]
Copy file name to clipboardExpand all lines: docs/modules/ROOT/pages/kotlin.adoc
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
==Kotlin
1
+
= Kotlin
2
2
3
3
In general, your Kotlin types should work out of the box with Morphia.
4
4
There are, however, a few interesting cases where they need a little extra help.
@@ -35,4 +35,4 @@ This module should support any
35
35
`ReadWriteProperty` type but is only currently tested against the `notNull()` case.
36
36
37
37
All that is needed to enable this more targeted support is to simply add the new dependency to your project as shown above and it should magically "Just Work™".
38
-
If you find something that doesn't work in your Kotlin project, please file an xref:/issues-help.adoc[issue].
38
+
If you find something that doesn't work in your Kotlin project, please file an xref:issues-help.adoc[issue].
0 commit comments