Skip to content

Commit

Permalink
DEVPROD-11594 Document BSON Text Format
Browse files Browse the repository at this point in the history
  • Loading branch information
Jess Balint committed Nov 4, 2024
1 parent c6f23a0 commit 593d340
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions source/extended-json/extended-json-query.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Extended JSON Query

## Abstract

Extended JSON query variation is a superset of Extended JSON. It is
intended to be used for serializing queries that can be specified in
the mongo shell. It supplements the Extended JSON syntax with support
for the following features:

- Trailing commas after the last value in an object

- NumberLong values in quotation marks

- Dates constructed with `new Date()` including an `ISODate` format

- Regex pattern enclosed in slashes

## Examples

### Trailing Comma
The following example shows an example of a JSON object with a trailing comma after the `b: 2` element. The trailing comma is supported only in objects, not in arrays. This is convenient when manually editing the text representation.
```javascript
{$match:
{a: 1,
b: 2,}
}
```

### Quoted NumberLong Value
The EJSON syntax supports a `NumberLong()` constructor but the argument must not be quoted. The following example shows the quoted version of the number.
```javascript
{$match:
{num:
{$gt: NumberLong("123456789")}
}}
```

### Date Constructor
The following example shows construction of a Date object with the date string represented in ISODate form.
```javascript
{$match:
{dateField:
{$lt: new Date("2019-10-23T08:58:17.868Z")}
}}
```

### Regex Pattern in Slashes
The following example shows a regex value enclosed in slashes. This is consistent with the MQL syntax.
```javascript
{$regexFindAll:
{input: \"$obj.obj.obj.obj.str\",
regex: /transparent|Forward/}
}
```

0 comments on commit 593d340

Please sign in to comment.