1

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

4

1 回答 1

5

您需要ObjectID比较ObjectID. 您正在做的是将 aObjectID与 a进行比较string

objectID, _ := primitive.ObjectIDFromHex("5c1760b4bd421c09e0f3140c")
filter = bson.M{"_id": bson.M{"$gt": objectID}}
cur, err := collection.Find(ctx, filter, &options)
于 2018-12-17T13:54:37.183 回答