from pymongo import MongoClient


class MongoWriter():
    DB_NAME = "tsinghua"
    COLLECTION = "goods"

    def __init__(self, collection = "goods"):
        client = MongoClient()
        db = client[self.DB_NAME]
        self.collection = db[collection]

    def insert(self, data):
        self.collection.insert(data) 

    def find(self, obj):
        return self.collection.find(obj).count()

@@ -26,17 +26,16 @@
 Client%0A%0A
-%0A
 class Mo
@@ -58,24 +58,44 @@
  DB_
-NAME = %22tsinghua
+HOST = %22spider%22%0A    DATABASE = %22demo
 %22%0A  
@@ -114,15 +114,20 @@
  = %22
-goods%22%0A
+supply%22%0A    
 %0A   
@@ -148,30 +148,8 @@
 self
-, collection = %22goods%22
 ):%0A 
@@ -176,16 +176,28 @@
 oClient(
+self.DB_HOST
 )%0A      
@@ -220,13 +220,14 @@
 lf.D
-B_NAM
+ATABAS
 E%5D%0A 
@@ -254,26 +254,31 @@
 on = db%5B
-collection
+self.COLLECTION
 %5D%0A%0A    d

simplify the mongo writer