Add filter conversion
This commit is contained in:
54
find.go
54
find.go
@@ -1,15 +1,9 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
// "log"
|
||||
"context"
|
||||
// "fmt"
|
||||
// "encoding/base64"
|
||||
|
||||
// "go.mongodb.org/mongo-driver/v2/mongo/options"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
|
||||
// "git.gsuntres.com/boxtep/boxtep/core"
|
||||
)
|
||||
|
||||
// Find is used to fetch the first page of data.
|
||||
@@ -20,16 +14,7 @@ func (c *MongoClient) Find(ctx context.Context, database, name string, filter bs
|
||||
|
||||
pageSize := max(limit, c.Limit)
|
||||
|
||||
|
||||
// id := DecodeCursor(nextCursor)
|
||||
|
||||
// filter["_id"] = bson.M{"_id": bson.M{"$gt": id}}
|
||||
// opts := options.Find().
|
||||
// SetLimit(pageSize + 1).
|
||||
// SetSort(bson.M{"_id": 1})
|
||||
// id := DecodeCursor(nextCursor)
|
||||
sort := bson.M{"_id": 1}
|
||||
// filter["_id"] = bson.M{"_id": bson.M{"$gt": id}}
|
||||
|
||||
pipeline := BuildPaginationPipeline(0, pageSize + 1, filter, sort)
|
||||
|
||||
@@ -91,16 +76,6 @@ func (c *MongoClient) Find(ctx context.Context, database, name string, filter bs
|
||||
out["next_cursor"] = nextCursor
|
||||
}
|
||||
|
||||
// _data, err := bson.Marshal(out)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// var r bson.M
|
||||
// if err := bson.Unmarshal(_data, &r); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
return out, nil
|
||||
}
|
||||
|
||||
@@ -109,8 +84,12 @@ func (c *MongoClient) FindOffset(ctx context.Context, database, name string, fil
|
||||
collection := c.GetCollection(database, name)
|
||||
|
||||
finalLimit := max(limit, c.Limit)
|
||||
|
||||
f := Mongofy(&Query{
|
||||
Filter: filter,
|
||||
})
|
||||
|
||||
pipeline := BuildPaginationPipeline(offset, finalLimit, filter, nil)
|
||||
pipeline := BuildPaginationPipeline(offset, finalLimit, f, nil)
|
||||
|
||||
// 2. Query
|
||||
cursor, err := collection.Aggregate(ctx, pipeline)
|
||||
@@ -163,24 +142,3 @@ func (c *MongoClient) FindOffset(ctx context.Context, database, name string, fil
|
||||
|
||||
return out, nil
|
||||
}
|
||||
// func (c *MongoClient) FindNext(ctx context.Context, database, name string, filter bson.M, nextCursor string, limit int64) ([]bson.M, error) {
|
||||
// collection := c.GetCollection(database, name)
|
||||
|
||||
// opts := options.Find().
|
||||
// SetLimit(max(limit, c.Limit)).
|
||||
// SetSort()
|
||||
|
||||
// cursor, err := collection.Find(ctx, filter)
|
||||
// if err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// var results []bson.M
|
||||
// if err = cursor.All(ctx, &results); err != nil {
|
||||
// return nil, err
|
||||
// }
|
||||
|
||||
// return results, err
|
||||
// }
|
||||
|
||||
// func EncodeCursor()
|
||||
|
||||
Reference in New Issue
Block a user