Skip to content

Commit 4e08bc3

Browse files
authored
Some corrections for db update return values (#554)
1 parent cb3d77c commit 4e08bc3

5 files changed

Lines changed: 16 additions & 6 deletions

File tree

docs/scripting/db/db.i.mdx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ If an \_id is included in the inserted document, that \_id will be used. This ha
2626

2727
:::warning
2828

29-
If a document is inserted containing an \_id that already exists in the user's database, a :::TRUST COMMUNICATION::: will be raised:
29+
If a document is inserted containing an \_id that already exists in the user's database, an error will be thrown:
3030

3131
`:::TRUST COMMUNICATION::: E11000 duplicate key error collection: hackmud*production.[user] index: \_id* dup key: { : [id value] } (11000)`
3232

3333
Any other documents inserted alongside the errant document will still be inserted.
34+
35+
You can catch these errors with `try`/`catch` if necessary. If you do not manually specify the `_id` fields of inserted documents, these errors should never happen.
3436
:::
3537

3638
## Return Data
3739

38-
An object is returned upon inserting one or many documents into the database, providing extra details about whether it succeeded:
40+
When inserting one document, an array of length 1 is returned, containing a single object, providing extra details about whether the insert succeeded:
3941

4042
| Key | Information |
4143
| ------ | --------------------------------------------------------------------------------- |
@@ -45,6 +47,14 @@ An object is returned upon inserting one or many documents into the database, pr
4547

4648
Other values are returned, but provide no additional usable data due to undefined conversions
4749

50+
When inserting an array of documents, a single object (_not_ an array) is returned, containing:
51+
52+
| Key | Information |
53+
| ------------ | ----------------------------------------- |
54+
| n | Number of documents inserted |
55+
| n_inserted | Number of documents inserted... again? |
56+
| inserted_ids | Array of `_id`s of the inserted documents |
57+
4858
## Example
4959

5060
```js

docs/scripting/db/db.r.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ All documents matched will be deleted, without confirmation. **An empty query (
2525

2626
## Return Data
2727

28-
An object is returned upon deleting documents with this function, providing extra details about whether it succeeded:
28+
An array of length 1 is returned, containing a single object, providing extra details about whether the deletion succeeded:
2929

3030
| Key | Information |
3131
| ------ | -------------------------------------------------------------------------------- |

docs/scripting/db/db.u.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Update operators can be used to set new individual values, increment integer val
2828

2929
## Return Data
3030

31-
An object is returned upon updating documents with this function, providing extra details about whether it succeeded:
31+
An array of length 1 is returned, containing a single object, providing extra details about whether the update succeeded:
3232

3333
| Key | Information |
3434
| --------- | ------------------------------------------------------------------------------ |

docs/scripting/db/db.u1.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Update operators can be used to set new individual values, increment integer val
2828

2929
## Return Data
3030

31-
An object is returned upon updating documents with this function, providing extra details about whether it succeeded:
31+
An array of length 1 is returned, containing a single object, providing extra details about whether the update succeeded:
3232

3333
| Key | Information |
3434
| --------- | ---------------------------------------------------------------------------------------------------- |

docs/scripting/db/db.us.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The conditions of the update will be applied to the new document alongside its i
3232

3333
## Return Data
3434

35-
An object is returned upon updating documents with this function, providing extra details about whether it succeeded:
35+
An array of length 1 is returned, containing a single object, providing extra details about whether the update succeeded:
3636

3737
| Key | Information |
3838
| --------- | ----------------------------------------------------------------------- |

0 commit comments

Comments
 (0)