M
M
Michael2016-03-18 09:02:23
MongoDB
Michael, 2016-03-18 09:02:23

How to implement normal relationships between docks in mgo golang??

Hello, I decided to try mongo, I found handles for it on the site for go - the MGO package .
so, to simple examples
of stucturing

type User struct{
Name string
Posts []Post
}
type Post struct{
Post string
}

in this version, we get a bunch of post structures inside the user structure, which is not very good
Option two
type User struct{
Name string

}
type Post struct{
User User.id
Post string
}

in this option, it turns out that something is ala sql relation, this option is certainly more fun, but how to rake it all out and display it on the page?
I see only 1 option so far, we create a structure that will
look absolutely the same as in the first option, and then fill it in two passes
the document is in the document, but there are no duplicates in the database.
I also looked at mgo.pipe and DBREFS , but if the skis don't work, I can't figure out how it works.. how can I organize all this better?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question