在mongodb中有一个用户数据已存储在集合中challange,数据似乎如下:
{
"_id" : 1,
"name" : "puneet",
"last" : "jindal",
"email" : "puneet@g.com"
}
{
"_id" : ObjectId("5b3af82cdb3aaa47792b5fd3"),
"name" : "hardeep",
"last" : "singh",
"email" : "hardeep@g.com"
}
{
"_id" : 3,
"name" : "gaurav",
"last" : "bansal",
"email" : "gaurav@g.com"
}
{
"_id" : ObjectId("5b3af87ddb3aaa47792b5fd4"),
"name" : "manish",
"last" : "jindal",
"email" : "manish@g.com"
}
Run Code Online (Sandbox Code Playgroud)
在上面的数据中有四个记录,其中两个具有整数形式的id,而另一个具有对象形式的id.我只想检索object idid字段中的所有记录.任何人都可以告诉我应该在代码中写什么查询,只会检索具有对象ID的记录.
更新:
我正在使用的代码:
type User struct {
Id bson.ObjectId `json:"_id" bson:"_id,omitempty"`
Name string `json:"name,omitempty" bson:"name,omitempty"`
Last string `json:"last,omitempty" …Run Code Online (Sandbox Code Playgroud)