Hey <!everyone> :wave: Today, we are issuing the ...
# prisma-whats-new
m
Hey <!everyone> ๐Ÿ‘‹ Today, we are issuing the
3.11.1
patch release. It's a big one for our MongoDB community ๐ŸŒฟ prisma rainbow ๐Ÿ“Œ All of the changes below are specific to the MongoDB Preview. This will be our last release before we announce MongoDB support as production-ready. Please, please, please give these changes a try and tell us know what you think in this issue or jump on a quick call with us. ๐Ÿป โ— Breaking: Filters no longer return
undefined
fields by default
In preparation for MongoDB General Availability, we've changed what data is returned when filtering MongoDB documents on
undefined
fields. The new rule is that
undefined
fields are excluded by default unless explicitly filtered for. This allows you to query for undefined and null values separately. Let's take a look at a concrete example. Given the following Prisma schema:
Copy code
model Address {
    id     Int    @id @map("_id")
    city   String
    street String? // Note that street is optional
}
For Mongo, optional fields can either be
null
or
undefined
(absent). The following documents are all valid for the schema above:
Copy code
{ "_id": 1, "city": "San Fransisco", "street": "Market st." }
{ "_id": 2, "city": "Seattle", "street": null }
{ "_id": 3, "city": "Chicago" }
Prior to
3.11.1
, if you queried for
where: { street: null }
, you'd get
_id: 2
and
_id: 3
. In
3.11.1
, you'll only get
_id: 2
. The ability to also query for the missing fields has also been added. For details, refer to the new
isSet
below to learn more. ๐Ÿช‘ New
isSet
filter operation
To compensate for missing fields on documents no longer being returned by the filters above, weโ€™ve added a new
isSet: bool
filter. This filter can be used to include fields that are
undefined
on documents. Using the example above, to include the
undefined
fields, you can use an `OR`:
Copy code
await prisma.address.findMany({
  where: {
    OR: [
      { street: { isSet: false } },
      { street: null }
    ]
  }
})
The
isSet
operation has been added to all scalar and embedded fields that are optional. ๐Ÿšฏ New
unset
operation
In
3.11.1
, you can also remove a field with the
unset
operation. Using the example above, let's write a query to remove the street field:
Copy code
await prisma.address.update({
  where: {
    id: 10,
  },
  data: {
    street: {
      unset: true,
    },
  },
})
This effectively sets the
street
field to
undefined
in the database. ๐Ÿ™ New
updateMany
embedded operation
We now support updating embedded documents that match specific criteria. For example, given the following schema:
Copy code
model Product {
  id          Int  @id @map("_id")
  name        String  @unique
  photos      Photo[]
}

type Photo {
  height Int    @default(200)
  width  Int    @default(100)
  url    String
}
Let's update the photo with a
url
of
1.jpg
to `2.png`:
Copy code
const product = prisma.product.update({
  where: {
    id: 10,
  },
  data: {
    photos: {
      updateMany: {
        where: {
          url: '1.jpg',
        },
        data: {
          url: '2.png',
        },
      },
    },
  },
})
โ›” New
deleteMany
embedded operation
Similar to
updateMany
, you can also remove embeds that match specific criteria. Using the Prisma Schema above, let's delete all photos with a
height
of 100:
Copy code
const product = prisma.product.update({
  where: {
    id: 10,
  },
  data: {
    photos: {
      deleteMany: {
        where: {
          height: 100,
        },
      },
    },
  },
})
๐Ÿ“š Learn more in the release notes For more info and links to documentation, you can read the release notes. ๐ŸŒŸ Help us spread the word about Prisma ๐ŸŒŸ To help spread the word about Prisma, weโ€™d very much appreciate it if you would star the repo ๐ŸŒŸ And if youโ€™re excited about the features in this weekโ€™s release, then help us and share your excitement on Twitter.
๐Ÿ‘Œ๐Ÿฟ 1
3๏ธโƒฃ 8
๐Ÿš€ 21
๐ŸŒฒ 6
๐Ÿคซ 3
๐Ÿ‡บ๐Ÿ‡ฟ 3
๐Ÿ† 5
america parrot 6
gopher love 3
๐Ÿ’ฏ 5
๐Ÿ’…๐Ÿผ 1
๐Ÿ‡บ๐Ÿ‡ธ 1
๐Ÿ‘Œ 30
๐Ÿ‡ฌ๐Ÿ‡ท 5
๐Ÿ‡จ๐Ÿ‡ฟ 6
๐Ÿ‡ณ๐Ÿ‡ฟ 5
๐Ÿ‘Ž 4
๐Ÿ‡ง๐Ÿ‡ท 3
๐Ÿณ๏ธโ€๐ŸŒˆ 3
๐Ÿ‡ฟ๐Ÿ‡ผ 6
prisma cool 9
๐Ÿ‡ณ๐Ÿ‡ฌ 3
prisma xmas 1
๐Ÿ˜ป 4
mongodb 3
prisma rainbow 5
๐Ÿ‡ฎ๐Ÿ‡ณ 3
๐Ÿ‡ฒ๐Ÿ‡ฌ 1
๐Ÿ‡จ๐Ÿ‡ด 1
๐Ÿ‡จ๐Ÿ‡ฎ 1
๐Ÿ‘ญ 12
๐ŸŽ‰ 27
๐Ÿ‡ฟ๐Ÿ‡ฆ 7
catjam 17
pakistan parrot 7
๐Ÿคท 4
๐Ÿ‘ 5
๐Ÿ‘Œ๐Ÿผ 2
๐Ÿ’ซ 5
party postgres 5
๐Ÿ˜ 5
๐Ÿฅฐ 3
๐Ÿ’… 2
๐Ÿ‡ณ๐Ÿ‡ด 1
๐Ÿ‡ท๐Ÿ‡ด 1
๐Ÿ‡ณ๐Ÿ‡ฑ 1
๐Ÿ‘ญ๐Ÿฝ 1
๐Ÿ‡ท๐Ÿ‡บ 1
๐Ÿ‡ฐ๐Ÿ‡ท 6
๐Ÿ‡ธ๐Ÿ‡ฐ 1
๐Ÿ‘Œ๐Ÿฝ 1
๐Ÿ‘ญ๐Ÿผ 1
๐Ÿ‡จ๐Ÿ‡ฒ 1