mongo allas 추가

This commit is contained in:
2023-06-20 09:59:11 +09:00
parent 6c41ff18a7
commit 15ba3e93d6

View File

@ -135,20 +135,25 @@ func (mc MongoClient) Collection(collname CollectionName) *mongo.Collection {
return mc.db.Collection(string(collname))
}
func (mc MongoClient) All(coll CollectionName, opts ...*options.FindOptions) ([]bson.M, error) {
func (mc MongoClient) AllAs(coll CollectionName, output any, opts ...*options.FindOptions) error {
cursor, err := mc.Collection(coll).Find(context.Background(), bson.D{}, opts...)
if err != nil {
return nil, err
return err
}
defer cursor.Close(context.Background())
var all []bson.M
err = cursor.All(context.Background(), &all)
err = cursor.All(context.Background(), output)
if err != nil {
return nil, err
return err
}
return all, nil
return nil
}
func (mc MongoClient) All(coll CollectionName, opts ...*options.FindOptions) ([]bson.M, error) {
var all []bson.M
err := mc.AllAs(coll, &all, opts...)
return all, err
}
func (mc MongoClient) FindOneAndDelete(coll CollectionName, filter bson.M, opts ...*options.FindOneAndDeleteOptions) (bson.M, error) {