Skip to content
/ mongol Public

mongoDB DBAL based on the official mongoDB Golang driver

License

Notifications You must be signed in to change notification settings

wajox/mongol

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

64 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mongol

License: MIT Go Reference codecov Go workflow Go Report Card

Model Example

type ExampleModel struct {
	mongol.BaseDocument `bson:",inline"`
	// Default fields from BaseDocument
	//
	// ID        primitive.ObjectID `json:"id,omitempty" bson:"_id,omitempty"`
	// CreatedAt time.Time          `json:"created_at" bson:"created_at"`
	// UpdatedAt time.Time          `json:"updated_at" bson:"updated_at"`

	Title string `json:"title,omitempty" bson:"title,omitempty"`
}

Storage usage example

storage, connErr = NewBaseCollection(context.TODO(), mongoURI, mongoDBName, mongoCollectionName)

m := &ExampleModel{}

id, saveErr := storage.InsertOne(context.TODO(), m)

Fiilter example

newM := &ExampleModel{}

err := storage.GetOneByFilter(
	context.TODO(),
	NewFilterBuilder().EqualTo("_id", m.ID).GetQuery(),
	newM,
)

if err != nil {
	fmt.Printf("%#v", newM)
}

Run tests

make test-all
MONGODB_URI=mongodb://localhost:27017 go test -a -v ./...