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