This commit is contained in:
Mike Schwörer 2023-06-07 11:28:07 +02:00
parent e89e2c18f2
commit a4b5f33d15
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 10 additions and 6 deletions

6
.idea/goext.iml generated
View File

@ -1,6 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<module type="WEB_MODULE" version="4"> <module type="WEB_MODULE" version="4">
<component name="Go" enabled="true" /> <component name="Go" enabled="true">
<buildTags>
<option name="goVersion" value="1.19" />
</buildTags>
</component>
<component name="NewModuleRootManager"> <component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" /> <content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />

View File

@ -58,6 +58,10 @@ func (c *Coll[TData]) List(ctx context.Context, filter ct.Filter, pageSize *int,
return entities, nextToken, nil return entities, nextToken, nil
} }
type countRes struct {
Count int64 `bson:"c"`
}
func (c *Coll[TData]) Count(ctx context.Context, filter ct.Filter) (int64, error) { func (c *Coll[TData]) Count(ctx context.Context, filter ct.Filter) (int64, error) {
pipeline := filter.FilterQuery() pipeline := filter.FilterQuery()
@ -68,12 +72,8 @@ func (c *Coll[TData]) Count(ctx context.Context, filter ct.Filter) (int64, error
return 0, err return 0, err
} }
type res struct {
Count int64 `bson:"c"`
}
if cursor.Next(ctx) { if cursor.Next(ctx) {
v := res{} v := countRes{}
err = cursor.Decode(&v) err = cursor.Decode(&v)
if err != nil { if err != nil {
return 0, err return 0, err