light modification
This commit is contained in:
parent
67b8215adf
commit
d1f6331ff8
@ -171,8 +171,8 @@ func (m *MongoDB) DeleteOne(id string, collection_name string) (int64, int, erro
|
|||||||
filter := bson.M{"_id": id}
|
filter := bson.M{"_id": id}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
opts := options.Delete().SetHint(bson.D{{Key: "_id", Value: 1}})
|
opts := options.Delete().SetHint(bson.D{{Key: "_id", Value: 1}})
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
//defer cancel()
|
||||||
|
|
||||||
result, err := targetDBCollection.DeleteOne(MngoCtx, filter, opts)
|
result, err := targetDBCollection.DeleteOne(MngoCtx, filter, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -192,8 +192,8 @@ func (m *MongoDB) DeleteMultiple(f map[string]interface{}, collection_name strin
|
|||||||
}
|
}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
opts := options.Delete().SetHint(bson.D{{Key: "_id", Value: 1}})
|
opts := options.Delete().SetHint(bson.D{{Key: "_id", Value: 1}})
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
//defer cancel()
|
||||||
|
|
||||||
result, err := targetDBCollection.DeleteMany(MngoCtx, filter, opts)
|
result, err := targetDBCollection.DeleteMany(MngoCtx, filter, opts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -215,8 +215,8 @@ func (m *MongoDB) UpdateMultiple(set interface{}, filter map[string]interface{},
|
|||||||
f = append(f, bson.E{Key: k, Value: v})
|
f = append(f, bson.E{Key: k, Value: v})
|
||||||
}
|
}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 50*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
//defer cancel()
|
||||||
res, err := targetDBCollection.UpdateMany(MngoCtx, f, dbs.InputToBson(doc, true))
|
res, err := targetDBCollection.UpdateMany(MngoCtx, f, dbs.InputToBson(doc, true))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.Logger.Error().Msg("Couldn't update resource: " + err.Error())
|
m.Logger.Error().Msg("Couldn't update resource: " + err.Error())
|
||||||
@ -234,8 +234,8 @@ func (m *MongoDB) UpdateOne(set interface{}, id string, collection_name string)
|
|||||||
bson.Unmarshal(b, &doc)
|
bson.Unmarshal(b, &doc)
|
||||||
filter := bson.M{"_id": id}
|
filter := bson.M{"_id": id}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 50*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
//defer cancel()
|
||||||
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(doc, true))
|
_, err := targetDBCollection.UpdateOne(MngoCtx, filter, dbs.InputToBson(doc, true))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
m.Logger.Error().Msg("Couldn't update resource: " + err.Error())
|
m.Logger.Error().Msg("Couldn't update resource: " + err.Error())
|
||||||
@ -253,8 +253,8 @@ func (m *MongoDB) StoreOne(obj interface{}, id string, collection_name string) (
|
|||||||
bson.Unmarshal(b, &doc)
|
bson.Unmarshal(b, &doc)
|
||||||
doc["_id"] = id
|
doc["_id"] = id
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
//defer cancel()
|
||||||
|
|
||||||
_, err := targetDBCollection.InsertOne(MngoCtx, doc)
|
_, err := targetDBCollection.InsertOne(MngoCtx, doc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -271,8 +271,8 @@ func (m *MongoDB) LoadOne(id string, collection_name string) (*mongo.SingleResul
|
|||||||
}
|
}
|
||||||
filter := bson.M{"_id": id}
|
filter := bson.M{"_id": id}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
//defer cancel()
|
||||||
|
|
||||||
res := targetDBCollection.FindOne(MngoCtx, filter)
|
res := targetDBCollection.FindOne(MngoCtx, filter)
|
||||||
if res.Err() != nil {
|
if res.Err() != nil {
|
||||||
@ -315,8 +315,8 @@ func (m *MongoDB) Search(filters *dbs.Filters, collection_name string) (*mongo.C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
// defer cancel()
|
||||||
if cursor, err := targetDBCollection.Find(
|
if cursor, err := targetDBCollection.Find(
|
||||||
MngoCtx,
|
MngoCtx,
|
||||||
f,
|
f,
|
||||||
@ -338,8 +338,8 @@ func (m *MongoDB) LoadFilter(filter map[string]interface{}, collection_name stri
|
|||||||
}
|
}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
|
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
//defer cancel()
|
||||||
|
|
||||||
res, err := targetDBCollection.Find(MngoCtx, f)
|
res, err := targetDBCollection.Find(MngoCtx, f)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -355,8 +355,8 @@ func (m *MongoDB) LoadAll(collection_name string) (*mongo.Cursor, int, error) {
|
|||||||
}
|
}
|
||||||
targetDBCollection := CollectionMap[collection_name]
|
targetDBCollection := CollectionMap[collection_name]
|
||||||
|
|
||||||
MngoCtx, cancel = context.WithTimeout(context.Background(), 10*time.Second)
|
MngoCtx, cancel = context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
//defer cancel()
|
||||||
|
|
||||||
res, err := targetDBCollection.Find(MngoCtx, bson.D{})
|
res, err := targetDBCollection.Find(MngoCtx, bson.D{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user