bson:“-”在插入时不会解组并忽略

时间:2018-09-03 14:49:47

标签: mongodb go mgo

我在$ lookup方面遇到了一些困难:

我的结构:

type Item struct {
    ID          bson.ObjectId   `json:"id" bson:"_id"`
    Name        string          `json:"name" bson:"name"`
    Description string          `json:"description" bson:"description"`
    CoverImage  bson.ObjectId   `json:"cover_image,omitempty" bson:"cover_image,omitempty"`
    GalleryList []*File
}

pipeline := []bson.M{
    bson.M{
        "$lookup": bson.M{
            "from":         "files",
            "localField":   "cover_image",
            "foreignField": "_id",
            "as":           "gallerylist",
    },
}

所以,我想做的是使用$ lookup获取具有“ cover_image”字段ID的集合“文件”上具有匹配ID的结构。

直到这里还可以,问题是:

如果'bson:"-"'在GalleryList上,则管道不会在现场解组。

例如:GalleryList []*File 'bson:"-"'

我不希望将GalleryList存储在mongo中。

我可以在GalleryList上做的任何事情都不会与其余结构一起插入。

我真的需要在前端将其删除还是在mongo上插入之前手动删除?

谢谢!

0 个答案:

没有答案
相关问题