Skip to content

Commit

Permalink
Link to 'Special rules for referential actions' from other pages (#4360)
Browse files Browse the repository at this point in the history
Co-authored-by: Jan Piotrowski <piotrowski+github@gmail.com>
Co-authored-by: Zach Tilev <103522279+zachtil@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 6, 2023
1 parent 73bd761 commit bb4cbd3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ When deleting a `User`, its existing posts' `authorUsername` field values will b

When the `username` of a `User` changes, its existing posts' `authorUsername` field values will be set to 'anonymous'.

### Database-specific requirements

MongoDB and SQL Server have specific requirements for referential actions if you have [self-relations](/concepts/components/prisma-schema/relations/referential-actions/special-rules-for-referential-actions#self-relation-sql-server-and-mongodb) or [cyclic relations](/concepts/components/prisma-schema/relations/referential-actions/special-rules-for-referential-actions#cyclic-relation-between-three-tables-sql-server-and-mongodb) in your data model. SQL Server also has specific requirements if you have relations with [multiple cascade paths](/concepts/components/prisma-schema/relations/referential-actions/special-rules-for-referential-actions#multiple-cascade-paths-between-two-models-sql-server-only).

## Upgrade paths from versions 2.25.0 and earlier

There are a couple of paths you can take when upgrading which will give different results depending on the desired outcome.
Expand Down
26 changes: 18 additions & 8 deletions content/200-concepts/200-database-connectors/07-mongodb.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -137,23 +137,33 @@ import { ObjectId } from 'bson'
const id = new ObjectId()
```

## Considerations
## Differences to connectors for relational databases

There are some considerations that come with adopting Prisma into your MongoDB project, these include:
This section covers ways in which the MongoDB connector differs from Prisma connectors for relational databases.

- Currently no plans to add support for [Prisma Migrate](/concepts/components/prisma-migrate) as MongoDB projects don't rely on internal schemas where changes need to be managed with an extra tool
- Management of `@unique` indexes is realized through `db push`
- [`@@id`](/reference/api-reference/prisma-schema-reference#id-1) and [autoincrement](/reference/api-reference/prisma-schema-reference#generate-auto-incrementing-integers-as-ids) are **not** supported.
### No support for Prisma Migrate

Currently, there are no plans to add support for [Prisma Migrate](/concepts/components/prisma-migrate) as MongoDB projects do not rely on internal schemas where changes need to be managed with an extra tool. Management of `@unique` indexes is realized through `db push`.

### No support for <inlinecode>@@id</inlinecode> and <inlinecode>autoincrement()</inlinecode>

The [`@@id`](/reference/api-reference/prisma-schema-reference#id-1) attribute (an ID for multiple fields) is not supported because primary keys in MongoDB are always on the `_id` field of a model.

The [`autoincrement()`](/reference/api-reference/prisma-schema-reference#generate-autoincrementing-integers-as-ids) function (which creates incrementing `@id` values) is not supported because `autoincrement()` does not work with the `ObjectID` type that the `_id` field has in MongoDB.

<!--For more information, refer to [Using Prisma with MongoDB](/content/300-guides/050-database/870-using-prisma-with-mongodb.mdx).-->

## Troubleshooting
### Cyclic references and referential actions

If you have cyclic references in your models, either from self-relations or a cycle of relations between models, and you use [referential actions](/concepts/components/prisma-schema/relations/referential-actions), you must set a referential action of `NoAction` to prevent an infinite loop of actions.

See [Special rules for referential actions](/concepts/components/prisma-schema/relations/referential-actions/special-rules-for-referential-actions) for more details.

### Error: Transactions are not supported by this deployment
### Replica set configuration

MongoDB only allows you to start a transaction on a replica set. Prisma uses transactions internally to avoid partial writes on nested queries. This means we inherit the requirement of needing a replica set configured.

When you try to use Prisma's MongoDB connector on a deployment that has no replica set configured, you can experience an error message as the following:
When you try to use Prisma's MongoDB connector on a deployment that has no replica set configured, Prisma shows the message `Error: Transactions are not supported by this deployment`. The full text of the error message is the following:

```
PrismaClientUnknownRequestError2 [PrismaClientUnknownRequestError]:
Expand Down

1 comment on commit bb4cbd3

@vercel
Copy link

@vercel vercel bot commented on bb4cbd3 Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

docs – ./

docs-prisma.vercel.app
docs-git-main-prisma.vercel.app
prisma2-docs.vercel.app

Please sign in to comment.