This commit is contained in:
cdle
2023-06-21 12:03:37 +08:00
parent c40ca23954
commit 3ca1543d3f
21 changed files with 308 additions and 257 deletions
+21
View File
@@ -70,6 +70,19 @@ func (cl *Collection) FindOne(filter interface{}) interface{} {
return result
}
func (cl *Collection) Aggregate(pipeline interface{}) interface{} {
cursor, err := cl.collection.Aggregate(context.Background(), pipeline)
if err != nil {
panic(cl.Vm.NewGoError(err))
}
var results = []map[string]interface{}{}
cursor.All(context.Background(), &results)
if err != nil {
panic(cl.Vm.NewGoError(err))
}
return results
}
func (cl *Collection) FindOneAndDelete(filter interface{}) interface{} {
var result = map[string]interface{}{}
err := cl.collection.FindOneAndDelete(context.Background(), filter).Decode(result)
@@ -152,6 +165,14 @@ func (cl *Collection) Find(filter interface{}, params map[string]interface{}) in
return results
}
func (cl *Collection) CountDocuments(filter interface{}) int64 {
v, err := cl.collection.CountDocuments(context.Background(), filter)
if err != nil {
panic(cl.Vm.NewGoError(err))
}
return v
}
func (cl *Collection) UpdateOne(filter, update interface{}, params map[string]interface{}) interface{} {
opts := []*options.UpdateOptions{}
if v, ok := params["upsert"]; ok {