go - Golang mongo-go-driver Beta 1 , using greater than operator
问题描述
I have been trying to get records greater than an _id provided The code is below
filter = bson.M{"_id": bson.M{"$gt": "5c1760b4bd421c09e0f3140c"}}
cur, err := collection.Find(ctx, filter, &options)
But iam always getting null values. I think i need to convert that id to object id But iam not sure how to do it in latest release There is a bson.TypeObjectID shown in predictions . Can someone please provide some details to do this.? Thanks
解决方案
您需要ObjectID
比较ObjectID
. 您正在做的是将 aObjectID
与 a进行比较string
。
objectID, _ := primitive.ObjectIDFromHex("5c1760b4bd421c09e0f3140c")
filter = bson.M{"_id": bson.M{"$gt": objectID}}
cur, err := collection.Find(ctx, filter, &options)
推荐阅读
- vue.js - v-model 中的空值
- jquery - Gridster.js 在页面加载时无法正确显示
- google-docs - 是否有任何方法可以一次修改谷歌文档的所有表的属性?
- bash - 当 remote:dir 和 (local)dir 相同时 sshfs 失败
- ios - 更改位置按钮图像 - Google Maps iOS SDK
- .net-core - 使用 Azure AD 进行身份验证时,从 Razor.Pages 项目中的 User.Identity 获取完整的用户名
- java - 如何将点击处理程序链接到片段以进行数据绑定?
- javascript - 检查数组的至少一个条件,并且不让它被以后的检查覆盖
- php - DSN 的 Debian 9 SendMail 问题
- swift - UICollectionviewcell 徽章隐藏在视图后面