Mutation for saving embedded list sort order?


Is it possible with Prisma to save the sort order of an embedded list when using the mongo db adapter?

One of the things that drew me in to using mongo as my database was being able to save arrays directly in my models and use that implicit array order as my sort order. But is it possible to modify and save that implicit sort order? Or would I need to add a field for position and save that explicitly?


Hey, can you give an example with queries of what you are trying to do? I don’t quite get it yet.


Say I have a model for a recipe like this:

type Recipe {
  id: ID! @id
  title: String!
  steps: [Step!]!

type Step @embedded {
  id: ID! @id
  directions: String!
  notes: String

And when the model is created, I end up with an array of embedded recipe steps…

id: 1111111
title: "Spaghett!"
steps: Array
  0: { ...step1}
  1: {...step2}

The sequence of the steps can be implied from the array’s order when it was created. However, if I want to later change the order so that “step2” is in the 0 position of the array, how would I do that with Prisma? Or is that even possible?

I hope that makes more sense…


Hey, no there currently is no way of changing the order in which embedded types are stored.

You would have to introduce a helper field for the position probably and then keep that up to date yourself.


This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.