Golang mongodb build reference relationship

Viewed 380

I have this one-to-many reference relationship in graphql with Mongo go driver.

type User {
    id: ObjectID!
    email: String!
    username: String!
    posts: [Post!]!
}

type Post {
    id: ObjectID!
    author: User!
    title: String!
    content: String!
}

I know that I can use the Aggregate framework to query the reference relationship.

However, What should I do if I want to create a user at the same time also create a post?

Sending two collection.InsertOne in the resolver?

0 Answers
Related