I am trying to migrate from mongoose to Prisma. Here is the model I have defined in mongoose which contains nested objects.
const sourceSchema = new Schema(
    {
        data: {
            national: {
                oldState: {
                    type: Array
                },
                currentState: {
                    type: Array
                }
            },
            sports: {
                oldState: {
                    type: Array
                },
                currentState: {
                    type: Array
                }
            }
        }
        
    }
);
Please guide me on how can I write the model in Prisma for the mongoose schema with nested objects.
You are looking for composite types to store nested objects in Prisma.
Here's how you can define the models:
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
  provider = "prisma-client-js"
}
datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}
model Source {
  id       String    @id @default(auto()) @map("_id") @db.ObjectId
  national stateType
  sports   stateType
}
type stateType {
  oldState     oldState
  currentState currentState
}
type oldState {
  type String[]
}
type currentState {
  type String[]
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With