Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api-reference/commands/diagnostic/hello.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,4 @@ The first value is the installed SQL extension version — the schema version, f

## Related content

- [DocumentDB Local](https://documentdb.io/docs/documentdb-local)
- [DocumentDB Local](https://documentdb.io/docs/documentdb-local/)
41 changes: 31 additions & 10 deletions api-reference/commands/query-and-write/delete.md
Comment thread
guanzhousongmicrosoft marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -146,31 +146,52 @@ Consider this sample document from the stores collection in the StoreData databa
}
```

### Example 1 - Delete all documents in a collection
The sample store above runs two promotion events, and three of its discounts are at 19%, so the filter `"promotionEvents.discounts.discountPercentage": 19` matches it. Each example below is independent and assumes the collection is fully populated; they are ordered so that the destructive one comes last.

### Example 1 - Delete a document that matches a specified query filter

```javascript
db.stores.deleteMany({})
db.stores.deleteOne({"_id": "0fcc0bf0-ed18-4ab8-b558-9848e18058f4"})
```

### Example 2 - Delete a document that matches a specified query filter
### Example 2 - Delete all documents that match a specified query filter

```javascript
db.stores.deleteOne({"_id": "68471088-4d45-4164-ae58-a9428d12f310"})
db.stores.deleteMany({"promotionEvents.discounts.discountPercentage": 19})
```

### Example 3 - Delete all documents that match a specified query filter
### Example 3 - Delete only one of many documents that match a specified query filter

Use `deleteOne` rather than `deleteMany`. There is no shell option that limits `deleteMany` to a single document — `limit` is a field of the wire-protocol `deletes` array element (see below), not a `deleteMany` option, and passing it here has no effect.

```javascript
db.stores.deleteMany({"promotionEvents.discounts.discountPercentage": 21}, {"limit": 0})
db.stores.deleteOne({"promotionEvents.discounts.discountPercentage": 19})
```

### Example 3 - Delete only one of many documents that match a specified query filter
### Example 4 - Delete all documents in a collection

An empty filter matches everything, so this empties the collection:

```javascript
db.stores.deleteMany({"promotionEvents.discounts.discountPercentage": 21}, {"limit": 1})
db.stores.deleteMany({})
```

## Wire protocol form

The shell helpers above are wrappers over the `delete` command. Each element of the `deletes` array carries its own `limit`, which must be `0` (delete every match) or `1` (delete at most one match); any other value is rejected with `The limit field in delete objects must be 0 or 1`.

```javascript
db.runCommand({
delete: "stores",
deletes: [
{ q: {"promotionEvents.discounts.discountPercentage": 19}, limit: 1 }
]
})
```

`deleteOne` sends `limit: 1`; `deleteMany` sends `limit: 0`.

## Related content

- [insert with DocumentDB](insert)
- [update with DocumentDB](update)
- [insert with DocumentDB](https://documentdb.io/docs/reference/commands/query-and-write/insert/)
- [update with DocumentDB](https://documentdb.io/docs/reference/commands/query-and-write/update/)
4 changes: 2 additions & 2 deletions api-reference/commands/query-and-write/find.md
Original file line number Diff line number Diff line change
Expand Up @@ -345,5 +345,5 @@ One of the documents returned shows the specified array elements projected in th

## Related content

- [insert with DocumentDB](insert)
- [update with DocumentDB](update)
- [insert with DocumentDB](https://documentdb.io/docs/reference/commands/query-and-write/insert/)
- [update with DocumentDB](https://documentdb.io/docs/reference/commands/query-and-write/update/)
36 changes: 20 additions & 16 deletions api-reference/commands/query-and-write/getMore.md
Comment thread
guanzhousongmicrosoft marked this conversation as resolved.
Comment thread
guanzhousongmicrosoft marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,49 @@ category: query-and-write

# getMore

The `getMore` command is used to retrieve extra batches of documents from an existing cursor. This command is useful when dealing with large datasets that can't be fetched in a single query due to size limitations. The command allows clients to paginate through the results in manageable chunks with commands that return a cursor. For example, [find](./find) and [aggregate](../aggregation/aggregate), to return subsequent batches of documents currently pointed to by the cursor.
The `getMore` command is used to retrieve extra batches of documents from an existing cursor. This command is useful when dealing with large datasets that can't be fetched in a single query due to size limitations. The command allows clients to paginate through the results in manageable chunks with commands that return a cursor. For example, [find](https://documentdb.io/docs/reference/commands/query-and-write/find/) and [aggregate](https://documentdb.io/docs/reference/commands/aggregation/aggregate/), to return subsequent batches of documents currently pointed to by the cursor.

## Syntax

The syntax for the `getMore` command is as follows:

```javascript
{
getMore: <cursor-id>,
db.runCommand({
getMore: NumberLong("<cursor-id>"),
collection: <collection-name>,
batchSize: <number-of-documents>
}
batchSize: <number-of-documents>,
maxTimeMS: <milliseconds>
})
```

- `getMore`: The unique identifier for the cursor from which to retrieve more documents.
- `getMore`: The unique identifier for the cursor from which to retrieve more documents, taken from the `cursor.id` field of the originating `find` or `aggregate` response. This field must be a BSON 64-bit integer — in `mongosh` write it as `NumberLong("...")`, and in Extended JSON as `{"$numberLong": "..."}`. A plain JavaScript number is serialized as a 32-bit integer and is rejected with `BadValue: getMore value should be an i64`.
- `collection`: The name of the collection associated with the cursor.
- `batchSize`: (Optional) The number of documents to return in the batch. If not specified, the server uses the default batch size.
- `batchSize`: (Optional) The maximum number of documents to return in the batch. Unlike the first page of `find` or `aggregate`, which defaults to 101 documents, `getMore` has no small default — if `batchSize` is omitted the server returns everything remaining in the cursor, stopping only when the accumulated batch reaches 16 MB.
- `maxTimeMS`: (Optional) A statement timeout for this batch. On a tailable cursor such as a change stream it instead bounds how long the server waits for new data.

## Examples

### Example 1: Retrieve more documents from a cursor

Assume you have a cursor with the ID `1234567890` from the `stores` collection. The following command retrieves the next batch of documents:
Assume you have a cursor with the ID `1234567890` from the `stores` collection. The following command retrieves up to five more documents:

```javascript
{
getMore: 1234567890,
db.runCommand({
getMore: NumberLong("1234567890"),
collection: "stores",
batchSize: 5
}
})
```

### Example 2: Retrieve more documents without specifying batch size
### Example 2: Drain the rest of the cursor

If you don't specify the `batchSize`, the server uses the default batch size:
Omitting `batchSize` returns every document still held by the cursor in a single batch, up to the 16 MB limit:

```javascript
{
getMore: 1234567890,
db.runCommand({
getMore: NumberLong("1234567890"),
collection: "stores"
}
})
```

A batch can come back smaller than requested, and an omitted `batchSize` does not guarantee the cursor was drained — the 16 MB batch limit can cut it short. Always keep calling `getMore` until the response reports a `cursor.id` of `0`, rather than stopping when a batch is shorter than `batchSize`.
14 changes: 7 additions & 7 deletions api-reference/commands/query-and-write/insert.md
Comment thread
guanzhousongmicrosoft marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ db.collection.insert(
| --- | --- |
| **`<single document or array of documents>`** | The document or array of documents to insert into the collection|
| **`writeConcern`** | (Optional) A document expressing the write concern. The write concern describes the level of acknowledgment requested from the server for the write operation|
| **`ordered`** | (Optional) If `true`, the server inserts the documents in the order provided. If `false`, the server can insert the documents in any order and will attempt to insert all documents regardless of errors|
| **`ordered`** | (Optional) Defaults to `true`. If `true`, the server inserts the documents in the order provided and stops at the first failure. If `false`, the server can insert the documents in any order and will attempt to insert all documents regardless of errors|

- `<single document or array of documents>`: The document or array of documents to insert into the collection.
- `writeConcern`: Optional. A document expressing the write concern. The write concern describes the level of acknowledgment requested from the server for the write operation.
- `ordered`: Optional. If `true`, the server inserts the documents in the order provided. If `false`, the server can insert the documents in any order and will attempt to insert all documents regardless of errors.
- `ordered`: Optional. Defaults to `true`. If `true`, the server inserts the documents in the order provided and stops at the first failure. If `false`, the server can insert the documents in any order and will attempt to insert all documents regardless of errors.

## Example(s)

Expand Down Expand Up @@ -237,7 +237,7 @@ If a duplicate value for the _id field is specified, a duplicate key violation e

### Inserting multiple documents in order

Documents that are inserted in bulk can be inserted in order when specifying "ordered": true
Documents inserted in bulk are inserted in the order provided, and the batch stops at the first failure. This is the default, so `ordered: true` below is explicit rather than required. Pass `ordered: false` instead when you want the server to attempt every document regardless of errors.

```javascript
db.stores.insertMany([
Expand Down Expand Up @@ -335,10 +335,10 @@ db.stores.insertMany([
}
]
}
], "ordered": true)
], { ordered: true })
```

The ordered insert command returns a response confirming the order in which documents were inserted:
A successful insert returns the ids of the inserted documents, keyed by their position in the input array. Note that `insertedIds` reports input positions, not execution order, so its shape is the same under `ordered: false` — it is not a way to confirm the order in which documents were applied:

```json
{
Expand All @@ -352,5 +352,5 @@ The ordered insert command returns a response confirming the order in which docu

## Related content

- [update with DocumentDB](update)
- [find with DocumentDB](find)
- [update with DocumentDB](https://documentdb.io/docs/reference/commands/query-and-write/update/)
- [find with DocumentDB](https://documentdb.io/docs/reference/commands/query-and-write/find/)
4 changes: 2 additions & 2 deletions api-reference/commands/query-and-write/update.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,5 +197,5 @@ db.stores.updateOne({"_id": "NonExistentDocId"}, {"$set": {"name": "Lakeshore Re

## Related content

- [insert with DocumentDB](insert)
- [delete with DocumentDB](delete)
- [insert with DocumentDB](https://documentdb.io/docs/reference/commands/query-and-write/insert/)
- [delete with DocumentDB](https://documentdb.io/docs/reference/commands/query-and-write/delete/)
32 changes: 19 additions & 13 deletions api-reference/operators/aggregation/$bucketauto.md
Comment thread
guanzhousongmicrosoft marked this conversation as resolved.
Comment thread
guanzhousongmicrosoft marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ category: aggregation

# $bucketAuto

The `$bucketAuto` stage categorizes documents into a specified number of buckets, attempting to evenly distribute the documents based on the values of a `groupBy` expression. Unlike [`$bucket`](./%24bucket.md), you do not have to provide boundaries — DocumentDB computes them for you.
The `$bucketAuto` stage categorizes documents into a specified number of buckets, attempting to evenly distribute the documents based on the values of a `groupBy` expression. Unlike [`$bucket`](https://documentdb.io/docs/reference/operators/aggregation/%24bucket/), you do not have to provide boundaries — DocumentDB computes them for you.

Supported since `v0.105-0`.

Expand Down Expand Up @@ -39,8 +39,11 @@ Supported since `v0.105-0`.
## Behavior

- `$bucketAuto` outputs documents with an `_id` of the form `{ "min": <lower>, "max": <upper> }`, representing the bucket's lower and upper boundary. The upper boundary is exclusive for all buckets except the last, which includes its upper boundary.
- When the number of distinct `groupBy` values is less than `buckets`, the stage produces fewer buckets than requested.
- When `granularity` is specified, the computed boundaries are rounded outward to the nearest preferred number.
- Without `granularity`, a non-last bucket's `max` is the first `groupBy` value of the *next* bucket, so adjacent buckets share a boundary. The last bucket's `max` is its own largest value.
- Documents are distributed as evenly as the input allows: with `n` documents and `b` buckets each bucket takes `floor(n / b)` documents, and a pool of `n mod b` spare documents is handed out one at a time to the buckets that need them, earliest first. A bucket is then extended to absorb any following documents that tie with its largest value, so that equal values never straddle a boundary. Each absorbed document consumes one of the spares, so when `n` is not divisible by `b` the extras do not always land in the earliest buckets.
- The stage can produce fewer buckets than requested — when the number of distinct `groupBy` values is less than `buckets`, and also whenever `granularity` rounding absorbs documents (see below).
- When `granularity` is specified, the first bucket's `min` is rounded down to the nearest series value strictly below it, and every bucket's `max` is rounded up to the nearest series value strictly above it; each later bucket's `min` is simply the previous bucket's `max`. Because a rounded-up `max` can exceed values that were assigned to later buckets, those documents are pulled into the current bucket, which is why the result often has fewer buckets than requested. Boundaries produced this way are doubles.
- With `granularity`, every `groupBy` value must be numeric and non-negative; a non-numeric value fails with `$bucketAuto only allows specifying a 'granularity' with numeric boundaries`.

## Examples

Expand Down Expand Up @@ -82,15 +85,17 @@ Sample output:

```json
[
{ "_id": { "min": 3, "max": 18 }, "count": 3, "avgPrice": 9.67 },
{ "_id": { "min": 18, "max": 45 }, "count": 3, "avgPrice": 28.33 },
{ "_id": { "min": 45, "max": 230 }, "count": 2, "avgPrice": 145 }
{ "_id": { "min": 3, "max": 18 }, "count": 3, "avgPrice": 7.666666666666667 },
{ "_id": { "min": 18, "max": 60 }, "count": 3, "avgPrice": 32.666666666666664 },
{ "_id": { "min": 60, "max": 230 }, "count": 2, "avgPrice": 145 }
]
```

Eight documents into three buckets gives sizes 3, 3, 2. The buckets hold prices `3, 8, 12`, then `18, 35, 45`, then `60, 230`. Each non-last bucket reports the next bucket's first price as its `max`, so the first bucket ends at `18` and the second at `60`.

### Example 2: Buckets with rounded boundaries via `granularity`

Group prices into four buckets rounded to a power-of-two series:
Request four buckets rounded to a power-of-two series:

```javascript
db.sales.aggregate([
Expand All @@ -108,14 +113,15 @@ Sample output:

```json
[
{ "_id": { "min": 2, "max": 16 }, "count": 3 },
{ "_id": { "min": 16, "max": 32 }, "count": 1 },
{ "_id": { "min": 32, "max": 64 }, "count": 2 },
{ "_id": { "min": 64, "max": 256 }, "count": 2 }
{ "_id": { "min": 2, "max": 16 }, "count": 3 },
{ "_id": { "min": 16, "max": 64 }, "count": 4 },
{ "_id": { "min": 64, "max": 256 }, "count": 1 }
]
```

Four buckets were requested but three are returned. The even split would have put `3, 8` in the first bucket, but rounding its `max` up from `8` to `16` pulls in `12` as well. The second bucket starts at `18`, and rounding its `max` up from `35` to `64` absorbs `45` and `60`, leaving only `230` for the third bucket.

## See Also

- [`$bucket`](./%24bucket.md) — fixed-boundary bucketing.
- [`$group`](./%24group.md) — generic grouping by an expression.
- [`$bucket`](https://documentdb.io/docs/reference/operators/aggregation/%24bucket/) — fixed-boundary bucketing.
- [`$group`](https://documentdb.io/docs/reference/operators/aggregation/%24group/) — generic grouping by an expression.
16 changes: 0 additions & 16 deletions api-reference/operators/arithmetic-expression/index.md

This file was deleted.

14 changes: 7 additions & 7 deletions getting-started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ DocumentDB consists of three primary components:

3. **pg_documentdb_gw**: The gateway that:
- Implements the MongoDB wire protocol
- Terminates TLS and authenticates clients (SCRAM-SHA-256 and Plain)
- Terminates TLS and authenticates clients (SCRAM-SHA-256)
- Translates MongoDB commands into calls against `pg_documentdb`
- Manages cursors, sessions, and connection state for MongoDB drivers

Expand All @@ -62,15 +62,15 @@ DocumentDB consists of three primary components:
Choose the getting started guide that best fits your needs:

### Quick Start Guides
- [VS Code Extension Quick Start](https://documentdb.io/docs/getting-started/vscode-quickstart) - Recommended for developers new to DocumentDB
- [VS Code Extension Guide](https://documentdb.io/docs/getting-started/vscode-extension-guide) - Comprehensive guide to the VS Code extension
- [VS Code Extension Quick Start](https://documentdb.io/docs/getting-started/vscode-quickstart/) - Recommended for developers new to DocumentDB
- [VS Code Extension Guide](https://documentdb.io/docs/getting-started/vscode-extension-guide/) - Comprehensive guide to the VS Code extension

### Language-Specific Guides
- [Python Setup Guide](https://documentdb.io/docs/getting-started/python-setup) - Using DocumentDB with Python applications
- [Node.js Setup Guide](https://documentdb.io/docs/getting-started/nodejs-setup) - Using DocumentDB with Node.js applications
- [Python Setup Guide](https://documentdb.io/docs/getting-started/python-setup/) - Using DocumentDB with Python applications
- [Node.js Setup Guide](https://documentdb.io/docs/getting-started/nodejs-setup/) - Using DocumentDB with Node.js applications

### Deployment Options
- [Pre-built Packages](https://documentdb.io/docs/getting-started/prebuilt-packages) - Download and install ready-to-use packages
- [Pre-built Packages](https://documentdb.io/docs/getting-started/prebuilt-packages/) - Download and install ready-to-use packages

## Community and Support

Expand All @@ -86,5 +86,5 @@ Choose the getting started guide that best fits your needs:
## Next Steps

After choosing your preferred getting started path:
- Explore our [API Reference](https://documentdb.io/docs/reference) for detailed documentation
- Explore our [API Reference](https://documentdb.io/docs/reference/) for detailed documentation
- Join our community to contribute and get support
Loading