payload: Payload V2 update and delete operations not working with Azure Cosmos DB for MongoDB
Link to reproduction
No response
Describe the Bug
We have encountered that with latest version of Payload there seem to be problems with Azure Cosmos DB for MongoDB with at least delete and update operations on collections. In our local development environment, we have been able to run payload v2 with latest image of mongo, so it seems the problems are related to azure cosmos DB and the way payload operates the database. We had no issues with Payload v1.8.3, so there seem to be regressions and/or changes with v2+Cosmos DB.
What works
- Creating collections without relationships
- Adding items to collections without relationships
- Updating collections without relationships
- Querying collections without relationships
What doesn’t work
- Deleting items in collections
- Updating collection with a relationship reference
What we have tried
- Starting with a clean database with Payload v2.1.1
- Verified that these problems do not reproduce with exact same code when using serverless mongodb atlas instance. We haven’t changed mongo connection string since migrating from v1.8.3 to v2.1.1 when connecting to Cosmos DB
- Index true/false in relationship definition
- useFacet true & false in config
- disableIndexHints true & false in config
- indexSortableFields true & false in config
The same “Transaction is not active” error is thrown with delete and update operations.
Collection
import { CollectionConfig } from "payload/types";
export const Cars: CollectionConfig = {
slug: "cars",
fields: [
{
name: "Name",
type: "text",
},
],
};
Global referencing collection
import { GlobalConfig } from "payload/types";
const GlobalTest: GlobalConfig = {
slug: "test",
fields: [
{ name: "title", type: "text" },
{
name: "Cars",
type: "relationship",
relationTo: "cars",
hasMany: true,
},
],
};
export default GlobalTest;
Config
export default buildConfig({
serverURL: process.env.PAYLOAD_PUBLIC_SERVER_URL,
indexSortableFields: true,
cors: "*",
admin: {
user: Users.slug,
bundler: webpackBundler(),
},
collections: [
Cars,
],
globals: [
GlobalTest,
],
editor: slateEditor({}),
db: mongooseAdapter({
url: process.env.MONGODB_URI,
disableIndexHints: true,
connectOptions: {
useFacet: false,
},
}),
});
Admin panel
Existing record in “Cars” collection
Adding reference to “Cars” from global collection
HTTP POST from Payload admin panel from “Save” button after adding reference to existing global collection:
-----------------------------
Content-Disposition: form-data; name="_payload"
{"Cars":["656465e724eceb71f72f18f6"],"title":"Test","updatedAt":"2023-11-27T09:49:41.889Z","createdAt":"2023-11-27T09:49:00.898Z"}
-----------------------------
HTTP response from payload API:
{"errors":[{"message":"Something went wrong."}]}
Error from Payload CMS logs:
2023-11-27T09:50:15.077216598Z [09:50:14] ERROR (payload): MongoServerError: Error=2, Details='Response status code does not indicate success: BadRequest (400); Substatus: 1101; ActivityId: XXXXXX; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 1101; ActivityId: XXXXX; Reason: (Response status code does not indicate success: BadRequest (400); Substatus: 1101; ActivityId: XXXXX; Reason: (Message: {"Errors":["Transaction is not active"]}
2023-11-27T09:50:15.077353351Z ActivityId: XXXXXX, Request URI: /apps/yyyyy/services/xxxx/partitions/zzzz/replicas/xxxxxxx/, RequestStats: Microsoft.Azure.Cosmos.Tracing.TraceData.ClientSideRequestStatisticsTraceDatum, SDK: Windows/10.0.17763 cosmos-netstandard-sdk/3.18.0);););
2023-11-27T09:50:15.077366295Z at Connection.onMessage (/home/node/app/node_modules/mongodb/lib/cmap/connection.js:231:30)
2023-11-27T09:50:15.077384048Z at MessageStream.<anonymous> (/home/node/app/node_modules/mongodb/lib/cmap/connection.js:61:60)
2023-11-27T09:50:15.077389127Z at MessageStream.emit (node:events:513:28)
2023-11-27T09:50:15.077393796Z at processIncomingData (/home/node/app/node_modules/mongodb/lib/cmap/message_stream.js:125:16)
2023-11-27T09:50:15.077397864Z at MessageStream._write (/home/node/app/node_modules/mongodb/lib/cmap/message_stream.js:33:9)
2023-11-27T09:50:15.077402122Z at writeOrBuffer (node:internal/streams/writable:392:12)
2023-11-27T09:50:15.077406300Z at _write (node:internal/streams/writable:333:10)
2023-11-27T09:50:15.077410567Z at Writable.write (node:internal/streams/writable:337:10)
2023-11-27T09:50:15.077414735Z at TLSSocket.ondata (node:internal/streams/readable:766:22)
2023-11-27T09:50:15.077419284Z at TLSSocket.emit (node:events:513:28)
Azure bicep
resource dbAccount 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = {
name: 'test-db-account'
location: 'westeurope'
kind: 'MongoDB'
properties: {
databaseAccountOfferType: 'Standard'
locations: [
{
locationName: 'westeurope'
failoverPriority: 0
}
]
capabilities: [
{
name: 'EnableServerless'
}
{
name: 'EnableMongo'
}
]
apiProperties: {
serverVersion: '4.2'
}
}
}
resource mongoDb 'Microsoft.DocumentDB/databaseAccounts/mongodbDatabases@2023-04-15' = {
parent: dbAccount
name: 'test-db'
properties: {
resource: {
id: 'test-db'
}
options: {}
}
}
To Reproduce
Both scenarios can be reproduced with Azure Cosmos DB for MongoDB database.
Relationship update repro
- Create two collections, A and B, where B is global
- Add one value to A from admin panel
- Reference the added value from global collection B from admin panel
Delete repro
- Create collection
- Add item in collection
- Delete from Admin panel
Payload Version
2.1.1
Adapters and Plugins
mongooseAdapter
About this issue
- Original URL
- State: closed
- Created 7 months ago
- Comments: 16 (10 by maintainers)
@DanRibbens Yes I’ve enabled it. The behaviour still seems flaky, it works sometimes and then it doesn’t, while indexSortableFields has been enabled. I have a lot of collections with relationships. I’ll report back if the issues come back again.