how to export cvs data from mongodb on centos7「建议收藏」

how to export cvs data from mongodb on centos7「建议收藏」Install mongodb-org-tools [lwk@qwfys:~]$ sudo dnf install mongodb-org-tools [sudo] password for lwk…

how to export cvs data from mongodb on centos7

Install mongodb-org-tools

[lwk@qwfys:~]$ sudo dnf install mongodb-org-tools
[sudo] password for lwk: 
Last metadata expiration check: 1:05:23 ago on Thu 16 Jul 2020 11:58:35 AM CST.
Dependencies resolved.
==============================================================================================================================================================================================================================================
 Package                                                        Architecture                                        Version                                                    Repository                                                Size
==============================================================================================================================================================================================================================================
Installing:
 mongodb-org-tools                                              x86_64                                              4.2.8-1.el8                                                mongodb-org                                               62 M

Transaction Summary
==============================================================================================================================================================================================================================================
Install  1 Package

Total download size: 62 M
Installed size: 128 M
Is this ok [y/N]: y
Downloading Packages:
mongodb-org-tools-4.2.8-1.el8.x86_64.rpm                                                                                                                                                                      4.1 MB/s |  62 MB     00:15    
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                                                                         4.0 MB/s |  62 MB     00:15     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                      1/1 
  Installing       : mongodb-org-tools-4.2.8-1.el8.x86_64                                                                                                                                                                                 1/1 
  Running scriptlet: mongodb-org-tools-4.2.8-1.el8.x86_64                                                                                                                                                                                 1/1 
  Verifying        : mongodb-org-tools-4.2.8-1.el8.x86_64                                                                                                                                                                                 1/1 

Installed:
  mongodb-org-tools-4.2.8-1.el8.x86_64                                                                                                                                                                                                        

Complete!
[lwk@qwfys:~]$ 

代码100分

Find specific data from mongodb

代码100分[lwk@qwfys:~]$ mongo -u lanzhou -p --host 192.168.3.88 --authenticationDatabase lanzhou
MongoDB shell version v4.2.8
Enter password: 
connecting to: mongodb://192.168.3.88:27017/?authSource=lanzhou&compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("6eb0c76d-338a-46ff-aa5a-65f468b76875") }
MongoDB server version: 4.2.8
> db.artists.find().pretty()
{
	"_id" : ObjectId("5f0fc3322d6c5971111129f4"),
	"artistname" : "The Tea Party"
}
{ "_id" : ObjectId("5f0fc3882d6c5971111129f5"), "artistname" : "The Kooks" }
{ "_id" : ObjectId("5f0fc3882d6c5971111129f6"), "artistname" : "Bastille" }
{
	"_id" : ObjectId("5f0fc3882d6c5971111129f7"),
	"artistname" : "Gang of Four"
}
{
	"_id" : ObjectId("5f0fc3b62d6c5971111129f8"),
	"artistname" : "Deep Purple",
	"albums" : [
		{
			"album" : "Machine Head",
			"year" : 1972,
			"genre" : "Rock"
		},
		{
			"album" : "Stormbringer",
			"year" : 1974,
			"genre" : "Rock"
		}
	]
}
{
	"_id" : ObjectId("5f0fc4032d6c5971111129f9"),
	"artistname" : "Robben Ford",
	"albums" : [
		{
			"album" : "Bringing it Back Home",
			"year" : 2013,
			"genre" : "Blues"
		},
		{
			"album" : "Talk to Your Daughter",
			"year" : 1988,
			"genre" : "Blues"
		}
	]
}
{
	"_id" : ObjectId("5f0fc4032d6c5971111129fa"),
	"artistname" : "Snoop Dogg",
	"albums" : [
		{
			"album" : "Tha Doggfather",
			"year" : 1996,
			"genre" : "Rap"
		},
		{
			"album" : "Reincarnated",
			"year" : 2013,
			"genre" : "Reggae"
		}
	]
}
{
	"_id" : 2,
	"artistname" : "Prince",
	"address" : {
		"street" : "Audubon Road",
		"city" : "Chanhassen",
		"state" : "Minnesota",
		"country" : "United States"
	}
}
{
	"_id" : 3,
	"artistname" : "Moby",
	"albums" : [
		{
			"album" : "Play",
			"year" : 1999,
			"genre" : "Electronica"
		},
		{
			"album" : "Long Ambients 1: Calm. Sleep.",
			"year" : 2016,
			"genre" : "Ambient"
		}
	]
}
{ "_id" : 4, "artistname" : "Rush" }
>

Export cvs data from mongodb


mongoexport --db lanzhou -u lanzhou -p Gah6kuP7ohfio4 --host 192.168.3.88 --collection artists --type=csv --fields _id,artistname --out /home/lwk/Downloads/.tmp/artists.csv

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
转载请注明出处: https://daima100.com/7302.html

(0)
上一篇 2023-03-22
下一篇 2023-03-22

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注