Skip to content

Commit

Permalink
Merge pull request #264 from Tobeyw/dev-mindy
Browse files Browse the repository at this point in the history
fix getBlocklist for wss
  • Loading branch information
Tobeyw authored Oct 10, 2024
2 parents 489e28f + 697c075 commit 0966979
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions neo3fura_ws/lib/cli/src.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"context"
"encoding/json"
"fmt"

"go.mongodb.org/mongo-driver/bson"
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"

log2 "neo3fura_ws/lib/log"
)

Expand Down Expand Up @@ -120,6 +122,59 @@ func (me *T) QueryAll(args struct {
return convert, count, nil
}

func (me *T) QueryAggregate(args struct {
Collection string
Index string
Sort bson.M
Filter bson.M
Pipeline []bson.M
Query []string
}, ret *json.RawMessage) ([]map[string]interface{}, error) {

var results []map[string]interface{}
convert := make([]map[string]interface{}, 0)
collection := me.C_online.Database(me.Db_online).Collection(args.Collection)
op := options.AggregateOptions{}
op.SetAllowDiskUse(true)

cursor, err := collection.Aggregate(context.TODO(), args.Pipeline, &op)

defer func(cursor *mongo.Cursor, ctx context.Context) {
err := cursor.Close(ctx)
if err != nil {
log2.Fatalf("Closing cursor error %v", err)
}
}(cursor, context.TODO())
if err == mongo.ErrNoDocuments {
return nil, fmt.Errorf("document not found")
}
if err != nil {
return nil, err
}
if err = cursor.All(context.TODO(), &results); err != nil {
return nil, fmt.Errorf("find documents error:%s", err)
}

for _, item := range results {
if len(args.Query) == 0 {
convert = append(convert, item)
} else {
temp := make(map[string]interface{})
for _, v := range args.Query {
temp[v] = item[v]
}
convert = append(convert, temp)
}
}

r, err := json.Marshal(convert)
if err != nil {
return nil, err
}
*ret = json.RawMessage(r)
return convert, nil
}

func (me *T) GetDistinctCount(args struct {
Collection string
Index string
Expand Down

0 comments on commit 0966979

Please sign in to comment.