Loading data from a JSON file
MySQL uses a format of a file with one JSON document per line to allow quick and easy import of documents into a database. To import JSON documents into collections in MySQL, we can use MySQL Shell with the util.importJson()
function.
For example, if you need to import a JSON file named languages.json
, then you write the following command:
util.importJson('/path/to/languages.json')
Ensure that you give the correct path to the JSON file.
In order to update the schema names, use the \rehash
command. Once you have updated the schema names, you can view the data of the collection using the following command:
db.languages.find()
You can also sort the details of a collection using the sort()
method. Here, you need to specify the column name inside the method. Consider a scenario where you need to sort the passenger details in the airports
file, and then find the airport having the highest number of passengers. In this case, you write...