|
@@ -0,0 +1,25 @@
|
|
|
+import pymongo
|
|
|
+
|
|
|
+
|
|
|
+class MongoDBConn:
|
|
|
+ def initConnect(self, host_port, db_name, assemble):
|
|
|
+ """
|
|
|
+ 建立数据库连接
|
|
|
+ """
|
|
|
+ # client = pymongo.MongoClient(host=host, port=port, username=user, password=password)
|
|
|
+ # db = client[db_name]
|
|
|
+ # collection = db[assemble]
|
|
|
+
|
|
|
+ myclient = pymongo.MongoClient(host_port)
|
|
|
+ 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)
|