mongo allas 추가
This commit is contained in:
17
mongo.go
17
mongo.go
@ -135,20 +135,25 @@ func (mc MongoClient) Collection(collname CollectionName) *mongo.Collection {
|
|||||||
return mc.db.Collection(string(collname))
|
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...)
|
cursor, err := mc.Collection(coll).Find(context.Background(), bson.D{}, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
defer cursor.Close(context.Background())
|
defer cursor.Close(context.Background())
|
||||||
|
|
||||||
var all []bson.M
|
err = cursor.All(context.Background(), output)
|
||||||
err = cursor.All(context.Background(), &all)
|
|
||||||
if err != nil {
|
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) {
|
func (mc MongoClient) FindOneAndDelete(coll CollectionName, filter bson.M, opts ...*options.FindOneAndDeleteOptions) (bson.M, error) {
|
||||||
|
|||||||
Reference in New Issue
Block a user