Browse Source

mangodb数据库连接测试成功

Air 4 weeks ago
parent
commit
dac2403179
2 changed files with 4 additions and 10 deletions
  1. 1 9
      src/kg_construction/mongodb_cache.py
  2. 3 1
      test/mangodb_test.py

+ 1 - 9
src/kg_construction/mongodb_cache.py

@@ -14,12 +14,4 @@ class MongoDBConn:
         mydb = myclient[db_name]
         collection = mydb[assemble]
 
-        return collection
-
-if __name__ == "__main__":
-    host_port = 'mongodb://222.24.30.227:27017/'
-    db_name = 'nebula-kg-cache'
-    assemble = 'mechatronics-seed'
-    mongoDBConn = MongoDBConn()
-    collection = mongoDBConn.initConnect(host_port=host_port, db_name=db_name, assemble=assemble)
-    print(collection)
+        return collection

+ 3 - 1
test/mangodb_test.py

@@ -1,9 +1,11 @@
 from src.kg_construction.mongodb_cache import MongoDBConn
 
 if __name__ == "__main__":
-    host_port = 'mongodb://222.24.30.227:27017/'
+    host_port = 'mongodb://8.142.150.114:27018/'
     db_name = 'nebula-kg-cache'
     assemble = 'mechatronics-seed'
     mongoDBConn = MongoDBConn()
     collection = mongoDBConn.initConnect(host_port=host_port, db_name=db_name, assemble=assemble)
+    triple_sample_templete = {"name":"ycj"}
+    collection.insert_one(triple_sample_templete)
     print(collection)