Browse Source

Merge branch 'master' of ssh://192.168.3.207:10022/BP/mongodb

wangchuanjin 4 years ago
parent
commit
ca1102ff8c
1 changed files with 20 additions and 1 deletions
  1. 20 1
      src/mongodb/mongodb.go

+ 20 - 1
src/mongodb/mongodb.go

@@ -28,6 +28,18 @@ func NewMgo(addr, db string, size int) *MongodbSim {
 	return mgo
 }
 
+func NewMgoWithUser(addr, db, uname, upwd string, size int) *MongodbSim {
+	mgo := &MongodbSim{
+		MongodbAddr: addr,
+		Size:        size,
+		DbName:      db,
+		UserName:    uname,
+		Password:    upwd,
+	}
+	mgo.InitPool()
+	return mgo
+}
+
 type Bluk struct {
 	ms     *MgoSess
 	writes []mongo.WriteModel
@@ -694,7 +706,6 @@ func ObjToMQ(query interface{}, isQuery bool) *bson.M {
 				}
 				data["_id"] = tmp
 			}
-
 		}
 	} else if s1, ok1 := query.(map[string]interface{}); ok1 {
 		data = s1
@@ -791,3 +802,11 @@ func autoUpdateTime(db, coll string, ue *bson.M) {
 		(*ue)["$set"] = set
 	}
 }
+
+func IsObjectIdHex(hex string) bool {
+	_, err := primitive.ObjectIDFromHex(hex)
+	if err != nil {
+		return false
+	}
+	return true
+}