MongoDB: Add `push` command support for embedded objects
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 47.6k
- Forks
- 2.5k
- Avg merge
- 21h 59m
- Merged PRs (30d)
- 95
Description
Suggested solution
Currently, Prisma does not support a 'push' command for array in embedded objects. It would be extremely useful to have a native 'push' command that allows us to update and add elements directly within array of embedded objects in the database.
Alternatives
As an alternative, we can first fire a find command, and then alter the array followed by a set command for the embedded object. However, these approaches are not as clean, efficient, as having a dedicated 'push' command in Prisma.
Additional context
The 'push' command for embedded objects would streamline the process of adding new items to an embedded array within a Prisma model. Currently, developers have to manually fetch the existing embedded object, update it in the application layer, and then save it back to the database. This process is cumbersome, especially when dealing with large arrays or frequent updates.
Having a 'push' command will not only improve developer productivity but also optimize database performance by reducing unnecessary reads.
Additionally, this feature aligns with the general expectations of modern ORMs and helps Prisma stay competitive in the market.
Below code doesn't work, a push inside embedded object should be supported.
return this.prisma.path.update({
where: {
id: id,
},
data: {
obj1: {
objarray: {
push: {
paramObj,
},
},
},
},
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the Prisma Client path.update example in the issue and trace how MongoDB updates handle embedded objects and arrays. Define support for push within an embedded array, then verify that the update works without the find-and-set workaround and that existing MongoDB update behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- mongodb, typescript
- Domain
- databases
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100