Add callback support for a counting

v2
Nikita Tokarchuk 4 years ago
parent 9fb3094b87
commit ee4bf46662
  1. 5
      mongox/database/count.go

@ -13,11 +13,14 @@ func (d *Database) Count(target interface{}, filters ...interface{}) (result int
collection := d.GetCollectionOf(target)
opts := options.Count()
composed := query.Compose(filters...)
ctx := query.WithContext(d.Context(), composed)
opts.Limit = composed.Limiter()
opts.Skip = composed.Skipper()
result, err = collection.CountDocuments(d.Context(), composed.M(), opts)
result, err = collection.CountDocuments(ctx, composed.M(), opts)
_ = composed.OnClose().Invoke(ctx, target)
return
}

Loading…
Cancel
Save