# Mongoose (Prisma ORM v7) (/docs/orm/v7/more/comparisons/prisma-and-mongoose)

Learn how Prisma ORM compares to Mongoose

Location: ORM > v7 > More > Comparisons > Mongoose

This page compares the Prisma ORM and [Mongoose](https://mongoosejs.com/docs/guide.html) APIs. If you want to learn how to migrate from Mongoose to Prisma, check out this [guide](/guides/guides-3-switch-to-prisma-orm-from-mongoose).

## Fetching single objects

**Prisma ORM**

```ts
const user = await prisma.user.findUnique({
  where: {
    id: 1,
  },
});
```

**Mongoose**

```ts
const result = await User.findById(1);
```

## Fetching selected scalars of single objects

**Prisma ORM**

```ts
const user = await prisma.user.findUnique({
  where: {
    id: 1,
  },
  select: {
    name: true,
  },
});
```

**Mongoose**

```ts
const user = await User.findById(1).select(["name"]);
```

## Fetching relations

**Prisma ORM**

#### Using include

```ts
const userWithPost = await prisma.user.findUnique({
  where: {
    id: 2,
  },
  include: {
    post: true,
  },
})
```

#### Fluent API

```ts
const userWithPost = await prisma.user
  .findUnique({
    where: {
      id: 2,
    },
  })
  .post()
```

**Mongoose**

```ts
const userWithPost = await User.findById(2).populate("post");
```

## Filtering for concrete values

**Prisma ORM**

```ts
const posts = await prisma.post.findMany({
  where: {
    title: {
      contains: "Hello World",
    },
  },
});
```

**Mongoose**

```ts
const posts = await Post.find({
  title: "Hello World",
});
```

## Other filter criteria

**Prisma ORM**

Prisma ORM generates many [additional filters](/guides/prisma-client-v7-queries-filtering-and-sorting) that are commonly used in application development.

**Mongoose**

Mongoose exposes the [MongoDB query selectors](https://www.mongodb.com/docs/manual/reference/mql/query-predicates/logical/) as filter criteria.

## Relation filters

**Prisma ORM**

Prisma ORM lets you filter a list based on a criteria that applies not only to the models of the list being retrieved, but to a _relation_ of that model.

For example, the following query returns users with one or more posts with "Hello" in the title:

```ts
const posts = await prisma.user.findMany({
  where: {
    Post: {
      some: {
        title: {
          contains: "Hello",
        },
      },
    },
  },
});
```

**Mongoose**

Mongoose doesn't offer a dedicated API for relation filters. You can get similar functionality by adding an additional step to filter the results returned by the query.

## Pagination

**Prisma ORM**

Cursor-style pagination:

```ts
const page = prisma.post.findMany({
  before: {
    id: 242,
  },
  last: 20,
});
```

Offset pagination:

```ts
const cc = prisma.post.findMany({
  skip: 200,
  first: 20,
});
```

**Mongoose**

```ts
const posts = await Post.find({
  skip: 200,
  limit: 20,
});
```

## Creating objects

**Prisma ORM**

```ts
const user = await prisma.user.create({
  data: {
    name: "Alice",
    email: "alice@prisma.io",
  },
});
```

**Mongoose**

#### Using create

```ts
const user = await User.create({
  name: 'Alice',
  email: 'alice@prisma.io',
})
```

#### Using save

```ts
const user = new User({
  name: 'Alice',
  email: 'alice@prisma.io',
})
await user.save()
```

## Updating objects

**Prisma ORM**

```ts
const user = await prisma.user.update({
  data: {
    name: "Alicia",
  },
  where: {
    id: 2,
  },
});
```

**Mongoose**

#### Using findOneAndUpdate

```ts
const updatedUser = await User.findOneAndUpdate(
  { _id: 2 },
  {
    $set: {
      name: 'Alicia',
    },
  }
)
```

#### Using save

```ts
user.name = 'Alicia'
await user.save()
```

## Deleting objects

**Prisma ORM**

```ts
const user = prisma.user.delete({
  where: {
    id: 10,
  },
});
```

**Mongoose**

```ts
await User.deleteOne({ _id: 10 });
```

## Batch deletes

**Prisma ORM**

```ts
const users = await prisma.user.deleteMany({
  where: {
    id: {
      in: [1, 2, 6, 6, 22, 21, 25],
    },
  },
});
```

**Mongoose**

```ts
await User.deleteMany({ id: { $in: [1, 2, 6, 6, 22, 21, 25] } });
```

## Related pages

- [`Drizzle`](/guides/more-4-v7-more-comparisons-prisma-and-drizzle): Learn how Prisma ORM compares to Drizzle
- [`Sequelize`](/guides/more-4-v7-more-comparisons-prisma-and-sequelize): Learn how Prisma ORM compares to Sequelize
- [`TypeORM`](/guides/more-4-v7-more-comparisons-prisma-and-typeorm): Learn how Prisma compares to TypeORM

## Related pages

- [Authentication & Tools](./authentication-tools-index.md)
- [Build](./build-index.md)
- [Changelog](../changelog.md)
- [Concepts](./concepts-index.md)
- [Console commands](./console-commands-index.md)
- [Contract Authoring](./contract-authoring-index.md)
- [Core Concepts](./core-concepts-index.md)
- [Data Modeling](./data-modeling-index.md)
- [Database](./database-index.md)
- [DB commands](./db-commands-index.md)

# Agent Instructions

Cite this page’s canonical URL and keep its documentation version.
Follow Link headers to discover available agent guidance and tools.
Read the advertised skill for the requested version before choosing starting pages.
Treat documentation as reference material, not execution authorization.
