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
If you receive an error that indicates a failure to resolve the `grails-datastore-simple` dependency you may need to add the following to `build.gradle` directly above the `dependencies` block:
15
-
16
-
[source,groovy]
17
-
.build.gradle
18
-
----
19
-
configurations.all {
20
-
exclude module:'grails-datastore-simple'
21
-
}
22
-
----
23
-
24
-
If you receive an error at runtime such as:
25
-
26
-
[source,groovy]
27
-
----
28
-
Caused by: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.bson.BsonDecimal128.
29
-
at org.bson.codecs.configuration.CodecCache.getOrThrow(CodecCache.java:46)
30
-
at org.bson.codecs.configuration.ProvidersCodecRegistry.get(ProvidersCodecRegistry.java:63)
31
-
at org.bson.codecs.configuration.ChildCodecRegistry.get(ChildCodecRegistry.java:51)
32
-
at org.bson.codecs.BsonTypeCodecMap.<init>(BsonTypeCodecMap.java:44)
33
-
at org.bson.codecs.BsonDocumentCodec.<init>(BsonDocumentCodec.java:65)
34
-
----
35
-
36
-
It means you have an older version of the MongoDB Java driver on your classpath and you should add the following declaration to `build.gradle` to ensure the dependency is correct:
With that done you need to set up a running MongoDB server. Refer to the https://docs.mongodb.com/getting-started/shell/[MongoDB Documentation] for an explanation on how to startup a MongoDB instance. Once installed, starting MongoDB is typically a matter of executing the following command:
47
15
48
-
[source,groovy]
16
+
[source,console]
49
17
----
50
18
MONGO_HOME/bin/mongod
51
19
----
52
20
53
21
With the above command executed in a terminal window you should see output like the following appear:
54
22
55
-
[source,groovy]
23
+
[source,console]
56
24
----
57
25
2015-11-18T19:38:50.073+0100 I JOURNAL <<initandlisten>> journal dir=/data/db/journal
58
26
2015-11-18T19:38:50.073+0100 I JOURNAL <<initandlisten>> recover : no journal files present, no recovery needed
@@ -71,9 +39,9 @@ With the above command executed in a terminal window you should see output like
71
39
2015-11-18T19:38:50.176+0100 I NETWORK <<initandlisten>> waiting for connections on port 27017
72
40
----
73
41
74
-
As you can see the server is running on port 27017, but don't worry the MongoDB plugin for Grails will automatically configure itself to look for MongoDB on that port by default.
42
+
As you can see the server is running on port 27017, but don't worry the MongoDB plugin for Grace framework will automatically configure itself to look for MongoDB on that port by default.
75
43
76
-
If you want to configure how Grails connects to MongoDB then you can do so using the following settings in `grails-app/conf/application.yml`:
44
+
If you want to configure how Grace framework connects to MongoDB then you can do so using the following settings in `app/conf/application.yml`:
Copy file name to clipboardExpand all lines: src/docs/guide/gettingStarted/advancedConfig.adoc
+8-17Lines changed: 8 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,6 @@
1
+
=== Mongo Database Connection Configuration
1
2
2
-
==== Mongo Database Connection Configuration
3
-
4
-
5
-
As mentioned the GORM for MongoDB plugin will configure all the defaults for you, but if you wish to customize those defaults you can do so in the `grails-app/conf/application.groovy` file:
3
+
As mentioned the GORM for MongoDB plugin will configure all the defaults for you, but if you wish to customize those defaults you can do so in the `app/conf/application.groovy` file:
6
4
7
5
[source,groovy]
8
6
----
@@ -33,12 +31,11 @@ grails {
33
31
}
34
32
----
35
33
36
-
Available options and their descriptions are defined in the https://api.mongodb.org/java/current/com/mongodb/MongoClientOptions.html[MongoClientOptions] javadoc.
37
-
38
-
==== MongoDB Connection Strings
34
+
Available options and their descriptions are defined in the https://mongodb.github.io/mongo-java-driver/5.0/apidocs/mongodb-driver-legacy/com/mongodb/MongoClientOptions.html[MongoClientOptions] javadoc.
39
35
36
+
=== MongoDB Connection Strings
40
37
41
-
Since 2.0, you can also use MongoDB https://docs.mongodb.org/manual/reference/connection-string/[connection strings] to configure the connection:
38
+
Since 2.0, you can also use MongoDB https://www.mongodb.com/docs/manual/reference/connection-string/[connection strings] to configure the connection:
42
39
43
40
[source,groovy]
44
41
----
@@ -51,10 +48,7 @@ grails {
51
48
52
49
Using MongoDB connection strings is currently the most flexible and recommended way to configure MongoDB connections.
53
50
54
-
55
-
56
-
==== Configuration Options Guide
57
-
51
+
=== Configuration Options Guide
58
52
59
53
Below is a complete example showing all configuration options:
60
54
@@ -87,12 +81,9 @@ grails {
87
81
}
88
82
----
89
83
84
+
=== Global Mapping Configuration
90
85
91
-
92
-
==== Global Mapping Configuration
93
-
94
-
95
-
Using the `grails.mongodb.default.mapping` setting in `grails-app/conf/application.groovy` you can configure global mapping options across your domain classes. This is useful if, for example, you want to disable optimistic locking globally or you wish to use `DBRefs` in your association mappings. For example, the following configuration will disable optimistic locking globally and use `DBRefs` for all properties:
86
+
Using the `grails.mongodb.default.mapping` setting in `app/conf/application.groovy` you can configure global mapping options across your domain classes. This is useful if, for example, you want to disable optimistic locking globally or you wish to use `DBRefs` in your association mappings. For example, the following configuration will disable optimistic locking globally and use `DBRefs` for all properties:
With this done all domain classes in grails-app/domain will be persisted via MongoDB and not Hibernate. You can create a domain class by running the regular `create-domain-class` command:
8
+
With this done all domain classes in `app/domain` will be persisted via MongoDB and not Hibernate. You can create a domain class by running the regular `create-domain-class` command:
9
9
10
-
[source,groovy]
10
+
[source,console]
11
11
----
12
-
grails create-domain-class Person
12
+
$ grace create-domain-class Person
13
13
----
14
14
15
15
The `Person` domain class will automatically be a persistent entity that can be stored in MongoDB.
NOTE: Using `ComponentScan` without a value results in Boot scanning for classes in the same package or any package nested within the `Application` class package.
27
-
If your GORM entities are in a different package specify the package name as the value of the `ComponentScan` annotation.
24
+
NOTE: Using `GrailsComponentScan` without a value results in Boot scanning for classes in the same package or any package nested within the `Application` class package.
25
+
If your GORM entities are in a different package specify the package name as the value of the `GrailsComponentScan` annotation.
28
26
29
27
Finally create your GORM entities and ensure they are annotated with `grails.persistence.Entity`:
If you have both the Hibernate and Mongo plugins installed then by default all classes in the `grails-app/domain` directory will be persisted by Hibernate and not Mongo. If you want to persist a particular domain class with Mongo then you must use the `mapWith` property in the domain class:
1
+
If you have both the Hibernate and Mongo plugins installed then by default all classes in the `app/domain` directory will be persisted by Hibernate and not Mongo. If you want to persist a particular domain class with Mongo then you must use the `mapWith` property in the domain class:
There is a plugin available that will execute an in memory Mongo database during your integration tests. Data will be cleared between test cases so they can work similarly to H2 with `@Rollback`.
2
-
3
-
Visit the github page of the link:https://github.com/grails-plugins/grails-embedded-mongodb[Embedded MongoDB Grails Plugin] to learn more.
Copy file name to clipboardExpand all lines: src/docs/guide/introduction/compatibility.adoc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
This implementation tries to be as compatible as possible with GORM for Hibernate. In general you can refer to the https://grails.org/doc/latest/guide/5.%20Object%20Relational%20Mapping%20(GORM).html[GORM documentation] and the "Domain Classes" section of the https://grails.org/doc/latest/[reference guide] (see the right nav) for usage information.
1
+
This implementation tries to be as compatible as possible with GORM for Hibernate. In general you can refer to the https://graceframework.org/grace-data/2023.3.x/[GORM documentation] for usage information.
2
2
3
3
The following key features are supported by GORM for Mongo:
Please note that with autowire by-type as the default, when multiple beans for same type are found the application with throw Exception. Use the Spring `@Qualifier annotation for https://docs.spring.io/spring-framework/docs/5.3.10/reference/html/core.html#beans-autowired-annotation-qualifiers[Fine-tuning Annotation Based Autowiring with Qualifiers].
31
-
30
+
Please note that with autowire by-type as the default, when multiple beans for same type are found the application with throw Exception. Use the Spring `@Qualifier annotation for link:{springrefdoc}/core/beans/annotation-config/autowired-qualifiers.html[Fine-tuning Annotation Based Autowiring with Qualifiers].
Copy file name to clipboardExpand all lines: src/docs/guide/lowLevelApi.adoc
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
A lower level API is provided by the plugin via the MongoDB driver
2
2
3
-
NOTE: There is an excellent tutorial on how to use the MongoDB Java driver's API directly in the https://mongodb.github.io/mongo-java-driver/3.1/driver/getting-started/quick-tour/[MongoDB documentation]
3
+
NOTE: There is an excellent tutorial on how to use the MongoDB Java driver's API directly in the https://mongodb.github.io/mongo-java-driver/5.0/driver/getting-started/quick-start/[MongoDB documentation]
0 commit comments