Python Forum

Full Version: Can't store pandas converted json dataframe into mongoDB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using the Quandl python api. I downloaded data and the data was returned into a pandas dataframe. I use to_json(None, orient='records') function and tried to insert it into my collection in the mongo db I get the following error "TypeError: document must be an instance of dict, bson.son.SON, bson.raw_bson.RawBSONDocument, or a type that inherits from collections.MutableMapping" how can I solve this problem?


import pandas as pd
import quandl
import pymonogo

def main():
data = quandl.get("WIKI/GOOG", returns="pandas")

data_json = data.to_json(None, orient='records')

client = pymongo.MongoClient('mongodb://localhost:27017/')

db = client.testdb

db.testdb.insert_many(data_json)

if __name__ == '__main__':main()
Please share the entire error code, so we can see line numbers and other info.

Otherwise, the error says it's expecting a dict, or a few other things. But instead, you're passing it something that's not one of those things. If I were to guess, data_json is a string.