Skip to content

slavabobik/greenleaf

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 

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

About

Simple query builder for MongoDB

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages