globalsign / mgo

The MongoDB driver for Go
Other
1.97k stars 230 forks source link

mongo查询数据集有点问题 #194

Closed fuckqqcom closed 6 years ago

fuckqqcom commented 6 years ago
  outs, err := bson.Marshal(m)
   query := bson.M{}
    for k, v := range m {
      query = bson.M{k: v}
   }
  // var result []ReFeedback
   var result1 []ReFeedback

count, err := c.Find(outs).Count()
conf.CheckErr(err)
if size > 50 {
    size = 50
}
c.Find(outs).All(&result1)
     //c.Find(bson.M{"SecuCode": "000001"}).Skip(page * size).Limit(size).Sort("-timeDate").All(&result)

image

你好:

同样都是用的outs这个结果,count可以查出来,但是下面的result1 查不出来,不是很理解,请教下博主

domodwyer commented 6 years ago

Hi @xhochipe

Your ReFeedback struct must have the same names, or bson tags:

type ReFeedback struct {
    Field1 string `bson:"field_name_1"`
    Field2 string `bson:"field_name_2"`
}

Where field_name_1 is the name in mongo.

If this doesn't work, please post a runnable example - good luck!

Dom

fuckqqcom commented 6 years ago

@domodwyer

fuckqqcom commented 6 years ago

{ "_id" : "788ec5fc913946d0f5f124d8f204af65", "author" : "符旸,宋进朝", "change" : "维持", "hashId" : "788ec5fc913946d0f5f124d8f204af65", "created_time" : "2018-06-13 17:25:30", "companyCode" : "10000590", "timeDate" : "2018-05-03 09:06:06", "insName" : "中航证券", "rate" : "买入", "secuName" : "平安银行", "sratingName" : "买入", "title" : "一季报点评:", "url" : "http://dat", "SecuCode" : "000001", "source" : "eastmoney", "show_url" : "https://g", "pdfUrl" : "http://pd", "flag" : 2 }

qq 20180626175037

dddd 那个文档集合和现在看到的mongo的数据集合是同一份数据,字段(field) 是相同的

domodwyer commented 6 years ago

Hi @xhochipe

It is very strange - do you have a test function I can run to reproduce? I tried something similar and it works OK for me.

Dom