Skip to content

Instantly share code, notes, and snippets.

@codenoid
Created October 24, 2021 17:01
Show Gist options
  • Save codenoid/37e39a475ce0f3dbcfd1f6e4d280d565 to your computer and use it in GitHub Desktop.
Save codenoid/37e39a475ce0f3dbcfd1f6e4d280d565 to your computer and use it in GitHub Desktop.
package main
import (
"context"
"fmt"
"time"
"github.com/qiniu/qmgo"
"gopkg.in/mgo.v2/bson"
)
func main() {
ctx := context.Background()
client, err := qmgo.NewClient(ctx, &qmgo.Config{Uri: "mongodb://localhost:27017"})
if err != nil {
panic(err)
}
db := client.Database("qmgo_date_test")
coll := db.Collection("test")
// coll.InsertOne(context.TODO(), bson.M{"date": time.Now(), "text": "hello"})
var item bson.M
coll.Find(context.TODO(), bson.M{"date": bson.M{"$lt": time.Now()}}).One(&item)
fmt.Println(item)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment