Golang mongodb build reference relationship
Asked Answered
M

0

6

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?

Montherlant answered 22/8, 2020 at 10:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.