dongsheng4679 2018-04-02 11:31
浏览 211
已采纳

从mongodb中提取嵌套的struct数据

Have a struct as follows

type Person struct {
   ID    bson.ObjectId `bson:"_id,omitempty"`
   Name  string        `json:"name"`
   Phone string        `json:"phone"`
}

and then want to nest it in another struct

type Customer struct {
   ID        bson.ObjectId `bson:"_id,omitempty"`
   StoreName string
   Person    Person        `json:"persons"`
}

instantiated as

customer := Customer{bson.NewObjectId(), "Seattle", p1}

and insterted into Mongo db (I am using the mgo driver for golang)

err = databaseConnection.Insert(&customer)

How do I retrieve the customer struct from the DB using parameters from the nested Person struct? E.g. pull all Customer structs that have a Person struct named “John”

I am trying

err = databaseConnection.Find(bson.M{XXXXXXXXX}).All(&resultsB)

but I can’t figure out what XXXXXX should be.

  • 写回答

1条回答 默认 最新

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 写c++代码,第7题说一下使用的计算方法
      • ¥15 postman接口自动化测试报告实践总结
      • ¥15 有关c++的问题,利用相关知识
      • ¥15 求香农编码和解码的matlab代码
      • ¥20 ROS中的TEB局部规划问题
      • ¥20 关于#matlab#的问题:要求测出上面图片中所有同心圆的半径
      • ¥20 epanet软件运行问题
      • ¥15 Python 文件读取
      • ¥60 dpabi进行Alff计算时脑池有干扰信号
      • ¥15 利用kmeans或kshape聚类分析对归一化的无量纲时间-降雨序列进行聚类