Skip to content

Commit c7b9f0f

Browse files
authored
fix(db-mongodb): disable join aggregations in DocumentDB compatibility mode (#13270)
### What? The PR #12763 added significant improvements for third-party databases that are compatible with the MongoDB API. While the original PR was focused on Firestore, other databases like DocumentDB also benefit from these compatibility features. In particular, the aggregate JOIN strategy does not work on AWS DocumentDB and thus needs to be disabled. The current PR aims to provide this as a sensible default in the `compatibilityOptions` that are provided by Payload out-of-the-box. As a bonus, it also fixes a small typo from `compat(a)bility` to `compat(i)bility`. ### Why? Because our Payload instance, which is backed by AWS DocumentDB, crashes upon trying to access any `join` field. ### How? By adding the existing `useJoinAggregations` with value `false` to the compatiblity layer. Individual developers can still choose to override it in their own local config as needed.
1 parent b3e48f8 commit c7b9f0f

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

docs/database/mongodb.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,21 +60,21 @@ You can access Mongoose models as follows:
6060

6161
## Using other MongoDB implementations
6262

63-
You can import the `compatabilityOptions` object to get the recommended settings for other MongoDB implementations. Since these databases aren't officially supported by payload, you may still encounter issues even with these settings (please create an issue or PR if you believe these options should be updated):
63+
You can import the `compatibilityOptions` object to get the recommended settings for other MongoDB implementations. Since these databases aren't officially supported by payload, you may still encounter issues even with these settings (please create an issue or PR if you believe these options should be updated):
6464

6565
```ts
66-
import { mongooseAdapter, compatabilityOptions } from '@payloadcms/db-mongodb'
66+
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
6767

6868
export default buildConfig({
6969
db: mongooseAdapter({
7070
url: process.env.DATABASE_URI,
7171
// For example, if you're using firestore:
72-
...compatabilityOptions.firestore,
72+
...compatibilityOptions.firestore,
7373
}),
7474
})
7575
```
7676

77-
We export compatability options for [DocumentDB](https://aws.amazon.com/documentdb/), [Azure Cosmos DB](https://azure.microsoft.com/en-us/products/cosmos-db) and [Firestore](https://cloud.google.com/firestore/mongodb-compatibility/docs/overview). Known limitations:
77+
We export compatibility options for [DocumentDB](https://aws.amazon.com/documentdb/), [Azure Cosmos DB](https://azure.microsoft.com/en-us/products/cosmos-db) and [Firestore](https://cloud.google.com/firestore/mongodb-compatibility/docs/overview). Known limitations:
7878

7979
- Azure Cosmos DB does not support transactions that update two or more documents in different collections, which is a common case when using Payload (via hooks).
8080
- Azure Cosmos DB the root config property `indexSortableFields` must be set to `true`.

packages/db-mongodb/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ export function mongooseAdapter({
331331
}
332332
}
333333

334-
export { compatabilityOptions } from './utilities/compatabilityOptions.js'
334+
export { compatibilityOptions } from './utilities/compatibilityOptions.js'
335335

336336
/**
337337
* Attempt to find migrations directory.

packages/db-mongodb/src/utilities/compatabilityOptions.ts renamed to packages/db-mongodb/src/utilities/compatibilityOptions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@ import type { Args } from '../index.js'
22

33
/**
44
* Each key is a mongo-compatible database and the value
5-
* is the recommended `mongooseAdapter` settings for compatability.
5+
* is the recommended `mongooseAdapter` settings for compatibility.
66
*/
7-
export const compatabilityOptions = {
7+
export const compatibilityOptions = {
88
cosmosdb: {
99
transactionOptions: false,
1010
useJoinAggregations: false,
1111
usePipelineInSortLookup: false,
1212
},
1313
documentdb: {
1414
disableIndexHints: true,
15+
useJoinAggregations: false,
1516
},
1617
firestore: {
1718
disableIndexHints: true,

test/generateDatabaseAdapter.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ export const allDatabaseAdapters = {
2222
},
2323
})`,
2424
firestore: `
25-
import { mongooseAdapter, compatabilityOptions } from '@payloadcms/db-mongodb'
25+
import { mongooseAdapter, compatibilityOptions } from '@payloadcms/db-mongodb'
2626
2727
export const databaseAdapter = mongooseAdapter({
28-
...compatabilityOptions.firestore,
28+
...compatibilityOptions.firestore,
2929
url:
3030
process.env.DATABASE_URI ||
3131
process.env.MONGODB_MEMORY_SERVER_URI ||

0 commit comments

Comments
 (0)