Skip to content

Commit adb4a4c

Browse files
Added mongodb aggregateRaw caveats
1 parent b3cea70 commit adb4a4c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

content/200-orm/200-prisma-client/150-using-raw-sql/200-raw-queries.mdx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,3 +851,18 @@ const result = await prisma.user.aggregateRaw({
851851

852852
- `pipeline`: An array of aggregation stages to process and transform the document stream via the [aggregation pipeline](https://www.mongodb.com/docs/manual/reference/operator/aggregation-pipeline).
853853
- `options`: Additional options to pass to the [`aggregate` command](https://www.mongodb.com/docs/manual/reference/command/aggregate/#command-fields).
854+
855+
:::info
856+
#### Caveats
857+
858+
When working with custom objects like `ObjectId` or `Date,` you will have to pass them according to the [MongoDB extended JSON Spec](https://www.mongodb.com/docs/manual/reference/mongodb-extended-json/#type-representations).
859+
Example:
860+
```ts no-lines
861+
const result = await prisma.user.aggregateRaw({
862+
pipeline: [
863+
{ $match: { _id: { $oid: id } } }
864+
// ^ notice the $oid convention here
865+
],
866+
});
867+
868+
```

0 commit comments

Comments
 (0)