From ebf9074345aeadaba668c7aa4cc93d5b8536c715 Mon Sep 17 00:00:00 2001 From: boyce Date: Tue, 9 Mar 2021 17:27:36 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A4=BA=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sysmodule/mongomodule/mongomodule_test.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/sysmodule/mongomodule/mongomodule_test.go b/sysmodule/mongomodule/mongomodule_test.go index 387ea38..38037b4 100644 --- a/sysmodule/mongomodule/mongomodule_test.go +++ b/sysmodule/mongomodule/mongomodule_test.go @@ -18,9 +18,14 @@ type Student struct { Status int `bson: "status"` } +type StudentName struct { + Name string `bson: "name"` +} + + func Test_Example(t *testing.T) { module:=MongoModule{} - module.Init("mongodb://admin:123456@127.0.0.1:27017",100, 5*time.Second,5*time.Second) + module.Init("mongodb://admin:123456@192.168.2.119:27017",100, 5*time.Second,5*time.Second) // take session s := module.Take() @@ -42,6 +47,7 @@ func Test_Example(t *testing.T) { Status: 1, } + //3.插入数据 err := c.Insert(&insertData) @@ -78,5 +84,12 @@ func Test_Example(t *testing.T) { //8.setoninsert使用 info,uErr := c.Upsert(bson.M{"_id":bson.ObjectIdHex("5f252f09999c622d36198951")},bson.M{ "$setOnInsert":bson.M{"Name":"setoninsert","Age":55}}) + + + //9.修改部分数字数据 + selector1 := bson.M{"_id":bson.ObjectIdHex("60473de655f1012e7453b369")} + update1 := bson.M{"$set":bson.M{"name":"xxxxx","age":1111}} + c.Update(selector1,update1) + fmt.Println(info,uErr) }