【问题标题】:json data is being stored as a single rowjson 数据被存储为单行
【发布时间】:2020-04-02 20:00:35
【问题描述】:
import json
from pymongo import MongoClient


client = MongoClient('localhost', 27017)
db = client['zomato_db']
collection_zomato = db['zomatores']


 with open('E:\\DAPProject\\Datasets\\ZOMATORES.json') as f:
 file_data = json.load(f)


  collection_zomato.insert_one(file_data)
  client.close()

当我尝试将数据存储在 mongodb 中时,它会存储为单行。 如何存储为多行?Output DataFrame

【问题讨论】:

  • 你的 json 文件的 schema 怎么样?..你可以添加它吗?

标签: python json pandas mongodb


【解决方案1】:

试试 insertMany() 方法

db.collection.insertMany(
   [ <document 1> , <document 2>, ... ],
   {
      writeConcern: <document>,
      ordered: <boolean>
   }
)

这是 mongodb 站点中的文档:https://docs.mongodb.com/manual/reference/method/db.collection.insertMany/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-02-06
    • 1970-01-01
    • 2020-07-30
    • 1970-01-01
    • 2017-11-14
    • 2017-09-17
    • 1970-01-01
    • 2015-03-18
    相关资源
    最近更新 更多