@@ -0,0 +1,40 @@
+package mongodb
+
+import (
+ "fmt"
+ "testing"
+)
+var mgo *MongodbSim
+func init() {
+ mgo = &MongodbSim{
+ MongodbAddr: "127.0.0.1:27017",
+ DbName: "wcc",
+ Size: 10,
+ UserName: "",
+ Password: "",
+ }
+ mgo.InitPool()
+}
+func TestMongodbSim_DropColl(t *testing.T) {
+ res := mgo.DropColl("wcc", "wcc_sbyj")
+ if res {
+ fmt.Println("删除成功")
+ } else {
+ fmt.Println("删除失败")
+func TestMongodbSim_Save(t *testing.T) {
+ data := map[string]interface{}{
+ "name": "wcc_wcc",
+ "title": "测试",
+ "content": "这是一个测试内容",
+ res := mgo.Save("wcc_wcc", data)
+ fmt.Println(res)
@@ -525,6 +525,19 @@ func (m *MongodbSim) Del(c string, q interface{}) bool {
return true
}
+//DropColl 删除数据表
+func (m *MongodbSim) DropColl(database, coll string) bool {
+ defer catch()
+ m.Open()
+ defer m.Close()
+ err := m.C.Database(database).Collection(coll).Drop(context.Background())
+ if err != nil {
+ log.Println("删除错误", err.Error())
+ return false
+ return true
//按条件更新
func (m *MongodbSim) Update(c string, q, u interface{}, upsert bool, multi bool) bool {
defer catch()