Python Forum
Can't store pandas converted json dataframe into mongoDB
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Can't store pandas converted json dataframe into mongoDB
#1
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()
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Question [Solved] Formatting cells of a pandas dataframe into an OpenDocument ods spreadsheet Calab 1 731 Mar-01-2025, 04:51 AM
Last Post: Calab
  Pandas and MongoDB question Majority390 1 1,468 Dec-23-2024, 02:41 AM
Last Post: sakshi009
  Find duplicates in a pandas dataframe list column on other rows Calab 2 2,261 Sep-18-2024, 07:38 PM
Last Post: Calab
  Find strings by index from a list of indexes in a different Pandas dataframe column Calab 3 1,662 Aug-26-2024, 04:52 PM
Last Post: Calab
  building a chatbot that fetches data from mongodb using RAG saisankalpj 0 1,039 Jul-10-2024, 04:49 PM
Last Post: saisankalpj
  Add NER output to pandas dataframe dg3000 0 1,174 Apr-22-2024, 08:14 PM
Last Post: dg3000
  HTML Decoder pandas dataframe column mbrown009 3 2,728 Sep-29-2023, 05:56 PM
Last Post: deanhystad
  Use pandas to obtain cartesian product between a dataframe of int and equations? haihal 0 2,040 Jan-06-2023, 10:53 PM
Last Post: haihal
  Pandas Dataframe Filtering based on rows mvdlm 0 2,094 Apr-02-2022, 06:39 PM
Last Post: mvdlm
  Pandas dataframe: calculate metrics by year mcva 1 3,456 Mar-02-2022, 08:22 AM
Last Post: mcva

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020