Add count operation
This commit is contained in:
parent
c752849518
commit
496f9541cb
12 changed files with 858 additions and 261 deletions
examples/getting-started
|
@ -35,4 +35,8 @@ type UserRepository interface {
|
|||
// The error will be returned only when error occurs while accessing the database. This is a MANY mode
|
||||
// because the first return type is an integer.
|
||||
DeleteByCity(ctx context.Context, city string) (int, error)
|
||||
|
||||
// CountByCity returns the number of rows that match the given city parameter. If an error occurs while
|
||||
// accessing the database, error value will be returned.
|
||||
CountByCity(ctx context.Context, city string) (int, error)
|
||||
}
|
||||
|
|
|
@ -60,3 +60,13 @@ func (r *UserRepositoryMongo) DeleteByCity(arg0 context.Context, arg1 string) (i
|
|||
}
|
||||
return int(result.DeletedCount), nil
|
||||
}
|
||||
|
||||
func (r *UserRepositoryMongo) CountByCity(arg0 context.Context, arg1 string) (int, error) {
|
||||
count, err := r.collection.CountDocuments(arg0, bson.M{
|
||||
"city": arg1,
|
||||
})
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return int(count), nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue