1

enter image description hereI have a mongodb connection(posted in image),which is having a collection of say some 20 files. i would like to read/load each collection from python and do the necessary computing.

Please find the sample below what i am trying to do.

import pandas as pd
import json
from pandas.io.json import json_normalize
from unittest.mock import inplace
from pymongo import MongoClient

connection = MongoClient('localhost', 27017)
db=connection.Tmobile
collection=db.collection_names(include_system_collections=False)
for collect1 in collection:
    print(collect1)
    with open(collect1,'r') as fi:
        d=json.load(fi)
        print(d)

when i try this it gives me below error.

Mynew Traceback (most recent call last): File "C:\Users\esrilka\eclipse-workspace\My First PyDev Project\dbsample.py", line 12, in with open(collect1,'r') as fi: FileNotFoundError: [Errno 2] No such file or directory: 'Mynew'

sri lakshmi
  • 47
  • 1
  • 9
  • Seem to be a [duplicate](https://stackoverflow.com/questions/16249736/how-to-import-data-from-mongodb-to-pandas?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa), especially you may find the `from odo import odo data = odo('mongodb://localhost/db::collection', pd.DataFrame)` interesting – prabhakar May 14 '18 at 06:36
  • Possible duplicate of [How to import data from mongodb to pandas?](https://stackoverflow.com/questions/16249736/how-to-import-data-from-mongodb-to-pandas) – yassadi May 14 '18 at 06:42

0 Answers0