https://github.com/mongorpc/mongorpc-go
mongorpc client for golang
https://github.com/mongorpc/mongorpc-go
client golang grpc mongodb mongorpc mongorpc-client
Last synced: 5 months ago
JSON representation
mongorpc client for golang
- Host: GitHub
- URL: https://github.com/mongorpc/mongorpc-go
- Owner: mongorpc
- License: apache-2.0
- Created: 2021-10-28T05:50:20.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2026-01-05T13:09:13.000Z (5 months ago)
- Last Synced: 2026-01-14T23:39:16.031Z (5 months ago)
- Topics: client, golang, grpc, mongodb, mongorpc, mongorpc-client
- Language: Go
- Homepage:
- Size: 185 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# mongorpc-go
Go client for MongoRPC - a gRPC proxy for MongoDB.
## Installation
```bash
go get github.com/mongorpc/mongorpc-go/mongorpc
```
## Quick Start
```go
package main
import (
"context"
"log"
"github.com/mongorpc/mongorpc-go/mongorpc"
)
func main() {
// Connect
client, err := mongorpc.NewClient("localhost:50051",
mongorpc.WithAPIKey("your-api-key"),
)
if err != nil {
log.Fatal(err)
}
defer client.Close()
ctx := context.Background()
users := client.Database("mydb").Collection("users")
// Insert
result, err := users.InsertOne(ctx, mongorpc.Document{
"name": "Alice",
"age": 30,
})
// Find by ID
doc, err := users.FindByID(ctx, result.InsertedID)
// Query builder
docs, err := users.Query().
Where("active", true).
Gte("age", 21).
SortDesc("createdAt").
Limit(10).
All(ctx)
// Update
_, err = users.UpdateByID(ctx, result.InsertedID, mongorpc.Update{
"$set": mongorpc.Document{"verified": true},
})
// Delete
_, err = users.DeleteByID(ctx, result.InsertedID)
}
```
## API
### Client
```go
client, err := mongorpc.NewClient(address,
mongorpc.WithAPIKey(key),
mongorpc.WithToken(jwt),
mongorpc.WithTimeout(10*time.Second),
)
```
### Collection Methods
| Method | Description |
|--------|-------------|
| `FindByID(ctx, id)` | Find by ID |
| `FindOne(ctx, filter)` | Find single document |
| `Find(ctx, filter, opts)` | Find documents |
| `InsertOne(ctx, doc)` | Insert document |
| `InsertMany(ctx, docs)` | Insert multiple |
| `UpdateByID(ctx, id, update)` | Update by ID |
| `UpdateOne/Many(ctx, filter, update)` | Update |
| `DeleteByID(ctx, id)` | Delete by ID |
| `DeleteOne/Many(ctx, filter)` | Delete |
| `CountDocuments(ctx, filter)` | Count |
| `Aggregate(ctx, pipeline)` | Aggregation |
| `Query()` | Fluent query builder |
### Query Builder
```go
users.Query().
Where("field", value).
Eq("field", value).
Gt("field", value).
In("field", values...).
Regex("field", "pattern").
Select("field1", "field2").
SortAsc("field").
SortDesc("field").
Limit(10).
Skip(20).
All(ctx)
```
## License
Apache-2.0