To install use:
go get github.com/slavabobik/greenleaf
package main
import (
"context"
"github.com/slavabobik/greenleaf"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
)
func main() {
ctx := context.TODO()
client, _ := mongo.Connect(ctx, options.Client().ApplyURI("mongodb://localhost:27017"))
collection := client.Database("testing").Collection("test")
doc := greenleaf.M{
"name": "Jhon",
"tags": []string{"fast", "furious"},
"score": 128,
"coins": 10000,
"active": true,
}
collection.InsertOne(ctx, doc)
filter := greenleaf.Filter(
greenleaf.Eq("name", "Jhon"),
greenleaf.In("tags", []string{"fast", "furious"}),
greenleaf.Gt("score", 100),
greenleaf.Lte("score", 200),
greenleaf.Exists("active", true),
)
}