0
users    path     common             config             
                  exchange_rate             
                  prod_data             
                  delivery_fee          

         site     shoppingmall       settings    description
                                                 highlight
                                                 prohibit_words

I did the following but failed.

db = MongoClient("localhost:99999").users
config_data = get_config()   --> just get config_data (json)
db.path.common.config.insert(config_data)

I would like to make it this way for each customer. What should I do? (I like examples because I am a beginner... (T.T)) thank you!!

susim
  • 221
  • 5
  • 15

1 Answers1

1

I think failed because your data is not json. if you want insert data from csv file you can try this :

import pandas as pd

from pymongo import MongoClient

import json



def mongoimport(csv_path, db_name, coll_name, db_url='localhost', db_port=27000)

    """ Imports a csv file at path csv_name to a mongo colection

    returns: count of the documants in the new collection

    """

    client = MongoClient(db_url, db_port)

    db = client[db_name]

    coll = db[coll_name]

    data = pd.read_csv(csv_path)

    payload = json.loads(data.to_json(orient='records'))

    coll.remove()

    coll.insert(payload)

    return coll.count()

this code simple to understand and this code from https://gist.github.com/jxub/f722e0856ed461bf711684b0960c8458