Initial import
This commit is contained in:
23
find_one.go
Normal file
23
find_one.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package mongo
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.mongodb.org/mongo-driver/v2/bson"
|
||||
)
|
||||
|
||||
// FindOne will return at most one document based on the filter provided.
|
||||
func (c *MongoClient) FindOne(ctx context.Context, database, name string, filter bson.M) (bson.M, error) {
|
||||
|
||||
// 1. Prepare to query.
|
||||
collection := c.GetCollection(database, name)
|
||||
|
||||
// 2. Query
|
||||
var out bson.M
|
||||
err := collection.FindOne(ctx, filter).Decode(&out)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return out, nil
|
||||
}
|
||||
Reference in New Issue
Block a user