Skip to content

slavabobik/greenleaf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🌱 greenleaf - simple, stateless, type safe and easy to use query builder for MongoDB.

build-img godoc codecov Go Report Card

Installation

To install use:

 go get github.com/slavabobik/greenleaf

Quick examples

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),
	)
}