Create a schema model without relationship - mongodb


#1

Hi,

How to create a schema model without relationship.

For example I would like to create schema model as below but I was getting an error. But I don’t want to create relation, I want to just store the Array of object data. How to achieve this. For example, My mongodb document should be as below

expected mongodb document

{
_id:“5d1f348230c49e000aa4f92f”,
name:“Prakash”,
gender: “male”,
posts:[{
title:“First”,
content:“First content”
},
{
title:“Second”,
content:“Second Content”

}

]
}

error:

 The field `posts` must provide a relation link mode. Either specify it on this field or the opposite field. Valid values are: `@relation(link: INLINE)`

datamodel.graphql

type User{
id: ID @id,
name: String,
gender: String,
posts: [Post!]!
}

type Post{
title: String!
content: String!
}


#2

Hi Team,

I have found an answer after long hours.

we have to use @embedded then it started to work.

datamodel.graphql

type User{
id: ID @id,
name: String,
gender: String,
posts: [Post!]!
}

type Post @embedded{
title: String!
content: String!
}