Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use MySQL skills to learn DBA in MongoDB Application skills

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

DBA application skills in how to use MySQL skills to learn MongoDB, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

1. MongoDB import and export

(1), mongoexport Export tool

MongoDB provides mongoexport tools that can export a collection to a file in json format or csv format. You can specify which data items to export, or you can export data based on a given condition. The tool help information is as follows:

Double-click the code to select 12 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 24 25 26 [root@localhost bin] #. / mongoexport-- helpoptions:-- help produce help message-v [--verbose] be more verbose (include multiple times for more verbosity e.g.-- vvvvv)-h [--host] arg mongo host to connect to (/ S1 for sets)-- port arg server port. Can also use-- host hostname:port-- ipv6 enable IPv6 support (disabled by default)-u [--username] arg username-p [--password] arg password-- dbpath arg directly access mongod database files in the given path, instead of connecting to a mongod server-needs to lock the data directory, so cannot be used if a mongod is currently accessing the same path-- directoryperdb if dbpath specified Each db is in a separate directory-d [--db] arg database to use-c [--collection] arg collection to use (some commands)-f [--fields] arg comma separated list of field names e.g.-f name,age-- fieldFile arg file with fields names-1 per line-Q [--query] arg query filter, as a JSON string-- csv export to csv instead of json-o [--out] arg output file If not specified, stdout is used-- jsonArray output to a json array rather than one object per line [root@localhost bin] #

Let's use a practical example to illustrate the use of this tool:

Export table T1 from the foo library to json format:

[root@localhost bin] #. / mongoexport-d foo-c T1-o / data/t1.json

Connected to: 127.0.0.1

Exported 1 records

[root@localhost bin] #

After the export is successful, let's take a look at the style of the / data/t1.json file to see if it is what we want:

[root@localhost data] # more t1.json

{"_ id": {"$oid": "4f927e2385b7a6814a0540a0"}, "age": 2}

[root@localhost data] #

Through the above instructions, the export is successful, but there is a problem, what if the migration of heterogeneous databases? For example, what should we do if we import MongoDB data into MySQL? MongoDB provides an export format of csv, which can solve the problem of heterogeneous database migration. The age and name columns of the T2 table of the foo library are exported as follows:

[root@localhost bin] #. / mongoexport-d foo-c T2-- csv-f age,name-o / data/t2.csv

Connected to: 127.0.0.1

Exported 1 records

[root@localhost bin] #

View the export results of / data/t2.csv:

[root@localhost data] # more t2.csv

Age,name

1, "wwl"

[root@localhost data] #

Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report