duanguochong0397 2019-04-15 14:00
浏览 216

我可以使用MongoDB官方Golang驱动程序查找记录,但是记录为空

I'm trying to learn Go and I wrote a little code that handles a MongoDB test database, inserting some general "items". This is the code:

https://pastebin.com/ptNwKbk2

I can insert and update records without issues but when I try to FindOne or Find a record what comes out is some empty shell, it finds the record but the record only shows its id.
First Find [line 89]:

err = collection.FindOne(context.TODO(), filter).Decode(&resultItem)

Result:

Found a single document: {ID:ObjectID("5cb488c30eeb652e64ecdaeb") itemID: priority:0 desc:}

Second Find [line 95]:

cur, err := collection.Find(context.TODO(), emptyFilter, findOptions)

Result, every element has an id but no data inside ("itemID: priority:0 desc:"):

Found multiple documents (array of pointers): [0xc00004c840 0xc00004c8c0]

Could someone find what the problem is here?

Thanks in advance

  • 写回答

1条回答 默认 最新

  • dopzc64662 2019-04-16 15:09
    关注

    The members of Items must start with an uppercase letter (just the variable names, the json/bson tags are fine) otherwise the deserializer can't access them.

    评论

报告相同问题?

悬赏问题

  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输