Skip to content

mondb defines an interface for mongodb driver. It makes it easy to operate the database only with Go native types.

License

Notifications You must be signed in to change notification settings

barbosaigor/mondb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MonDB

MonDB defines an interface for mongodb driver.
It makes it easy to operate the database only with Go native types.

Installation

go get github.com/barbosaigor/mondb

Usage

The user must make a connection to database and after all close it.

db := New("dealership", "cars")
if err := db.Conn("mongodb://your-mongo-cluster:27017"); err != nil {
    // ...
}
defer db.Discn()
// Now you can have fun

e.g Find documents

db := New("dealership", "cars")
// ...
filter := map[string]interface{}{"year": 1964}
cars, err := db.FindMany(filter)

e.g Find a document

filter := map[string]interface{}{"name": "A car", "price": 1500.7}
car, err := db.FindOne(filter)

e.g Insert a document

car := map[string]interface{}{
    "name": "A car", 
    "price": 1000.49, 
    "year": 1943
}
err := db.InsertOne(car)

e.g update params of a document

filter := map[string]interface{}{"name": "A car"}
car := map[string]interface{}{
    "name": "The car", 
    "year": 2001
}
wasUpdated, err := db.UpdateOne(filter, car)

e.g delete a document

filter := map[string]interface{}{"name": "The car"}
wasDeleted, err := db.DeleteOne(filter)

For more information check out documentation.

About

mondb defines an interface for mongodb driver. It makes it easy to operate the database only with Go native types.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages