|
2 | 2 | FAQ
|
3 | 3 | ===
|
4 | 4 |
|
5 |
| -.. default-domain:: mongodb |
6 |
| - |
7 | 5 | .. contents:: On this page
|
8 | 6 | :local:
|
9 | 7 | :backlinks: none
|
@@ -153,6 +151,52 @@ When ``MongoClient.close()`` is called by any thread, the driver
|
153 | 151 | closes all idle sockets and closes all sockets that are in
|
154 | 152 | use as they are returned to the pool.
|
155 | 153 |
|
| 154 | + |
| 155 | +How do I prevent the "IllegalArgumentException: Invalid BSON field name" error? |
| 156 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 157 | + |
| 158 | +Your application may throw this exception if you pass an incorrectly formatted |
| 159 | +document to an operation and you are using a driver version v4.7 or earlier. |
| 160 | + |
| 161 | +.. note:: |
| 162 | + |
| 163 | + In driver versions v4.8 and later, this error message was replaced by one |
| 164 | + that includes more specific details on what was incorrectly formatted. |
| 165 | + |
| 166 | +For example, the driver throws this error when you call an update operation |
| 167 | +and incorrectly omit the update operator as shown in the following code |
| 168 | +example: |
| 169 | + |
| 170 | +.. code-block:: java |
| 171 | + :emphasize-lines: 4 |
| 172 | + :copyable: false |
| 173 | + |
| 174 | + // incorrectly formatted update document |
| 175 | + collection.updateOne( |
| 176 | + new Document().append("name", "fizz"), |
| 177 | + new Document().append("name", "buzz") |
| 178 | + ); |
| 179 | + |
| 180 | +To avoid this error, use the builder class for the appropriate operation. |
| 181 | +The driver offers builder classes to create syntactically correct BSON for |
| 182 | +MongoDB operations. The prior example can be correctly expressed using |
| 183 | +the builder classes as shown in the following code example: |
| 184 | + |
| 185 | +.. code-block:: java |
| 186 | + :emphasize-lines: 7 |
| 187 | + :copyable: false |
| 188 | + |
| 189 | + // Builder class imports |
| 190 | + import static com.mongodb.client.model.Filters.*; |
| 191 | + import static com.mongodb.client.model.Updates.*; |
| 192 | + |
| 193 | + // ... |
| 194 | + |
| 195 | + collection.updateOne(eq("name", "fizz"), set("name", "buzz")); |
| 196 | + |
| 197 | +To learn more about the available builders classes, see the :ref:`<java-builders>` documentation. |
| 198 | + |
| 199 | + |
156 | 200 | How do I prevent the "IllegalStateException: state should be: open" error?
|
157 | 201 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
158 | 202 |
|
@@ -182,6 +226,7 @@ after any code that calls ``close()`` on it.
|
182 | 226 | To learn more about accessing MongoDB from Spring Boot, see
|
183 | 227 | `Spring Boot and MongoDB <https://www.mongodb.com/compatibility/spring-boot>`__.
|
184 | 228 |
|
| 229 | + |
185 | 230 | POJOs
|
186 | 231 | -----
|
187 | 232 |
|
|
0 commit comments