Quantcast
Channel: User Norbert - Stack Overflow
Viewing all articles
Browse latest Browse all 42

Answer by Norbert for How to return aggregated document from MongoDB in Golang?

$
0
0

The error states that the category is an array instead of just a string.

Your current definition:

type Post struct {    ID          primitive.ObjectID       `json:"_id" bson:"_id,omitempty"`    Title       *string                  `json:"title" bson:"title"`    Slug        *string                  `json:"slug" bson:"slug"`    Content     []map[string]interface{} `json:"content" bson:"content,omitempty"`    Category    *string                  `json:"category" bson:"category,omitempty"`}

Should look like:

type Post struct {    ID          primitive.ObjectID       `json:"_id" bson:"_id,omitempty"`    Title       *string                  `json:"title" bson:"title"`    Slug        *string                  `json:"slug" bson:"slug"`    Content     []map[string]interface{} `json:"content" bson:"content,omitempty"`    Category    []*string                  `json:"category" bson:"category,omitempty"`}

Where Category []*string might still need some tweaking:The pointer to string could also just be a string.

(Not knowing this return from Mongo and not having one running to test):

Another option is that the category is a byte array, and that the type has to be []byte.


Viewing all articles
Browse latest Browse all 42

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>