howtoexportcvsdatafrommongodboncentos7
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:~]$
Find specific data from mongodb
[lwk@qwfys:~]$ mongo -u lanzhou -p --host 192.168.3.88 --authenticationDatabase lanzhouMongoDB 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
以上是 howtoexportcvsdatafrommongodboncentos7 的全部内容, 来源链接: utcz.com/z/534664.html