Linux中mongodb安装和导出为json

采用官方工具导出mongo数据为json格式

文档:https://docs.mongodb.com/manual/reference/program/mongoexport/

可以远程导出,只要有host:port即可。

首先需要安装tools:

在redhat中:

文档:https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/

1、编写repo文件

Create a /etc/yum.repos.d/mongodb-org-3.2.repo file so that you can install MongoDB directly, using yum.

1
2
3
4
5
6
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

  

2.选择安装功能

一共有以下几种选择

mongodb-org metapackage that will automatically install the four component packages listed below.
mongodb-org-server Contains the mongod daemon and associated configuration and init scripts.
mongodb-org-mongos Contains the mongos daemon.
mongodb-org-shell Contains the mongo shell.
mongodb-org-tools Contains the following MongoDB tools: mongoimport bsondumpmongodump,mongoexportmongofilesmongooplogmongoperfmongorestoremongostat, and mongotop.

如果全部安装:

sudo yum install -y mongodb-org

如果只安装tools

sudo yum install -y mongodb-org-tools

 

3.导出json

1
2
3
4
5
6
7
8
9
10
11
12
13
sudo mongoexport -h $mongoDBUri --db $db_name  -c $collection_name  -q '{
    $or:[
        {"alerts.FamilyFriendly.completed":false},
        {"alerts.GasAndSafety.completed":false},
        {"alerts.Breakfast.completed":false},
        {"alerts.SpokenLanguage.completed":false},
        {"alerts.LocationHighlights.completed":false},
        {"alerts.AccessibilityEnsure.completed":false},
        {"alerts.AirportShuttle.completed":false},
        {"alerts.RoomSize.completed":false},
        {"alerts.Renovations.completed":false}
    ]
}' -f hotelId,alerts   -o $OUTPUTDIR/contentScore-$(date +%F)-e.json --jsonArray
  • -h  host:port
  • --db db
  • -c collections
  • -q query string,查询语法
  • -f  选择导出字段
  • -o  导出文件
  • --jsonArray 导出为数组,默认为{}{}{}...

 

 





posted @   Ryan.Miao  阅读(3817)  评论(0编辑  收藏  举报
编辑推荐:
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示