Skip to content
Studio 3T - The professional GUI, IDE and client for MongoDB
  • Tools
    • Aggregation Editor
    • IntelliShell
    • Visual Query Builder
    • Export Wizard
    • Import Wizard
    • Query Code
    • SQL Query
    • Connect
    • Schema Explorer
    • Compare
    • SQL ⇔ MongoDB Migration
    • Data Masking
    • Task Scheduler
    • Reschema
    • More Tools and Features
  • Solutions
  • Resources
    • Knowledge Base
    • MongoDB Tutorials & Courses
    • Tool/Feature Documentation
    • Blog
    • Community
    • Testimonials
    • Whitepapers
    • Reports
  • Contact us
    • Contact
    • Sales Support
    • Feedback and Support
    • Careers
    • About Us
  • Store
    • Buy Now
    • Preferred Resellers
    • Team Pricing
  • Download
  • My 3T
search

Academy 3T

  • Explore our courses
    • MongoDB 101: Getting Started
    • MongoDB 201: Querying MongoDB Data
    • MongoDB 301: Aggregation
  • Get certified

Lesson 6, Exercise 1: Importing document data from a .csv file

MongoDB 101: Getting Started Importing and Exporting MongoDB Data Lesson 6, Exercise 1: Importing document data from a .csv file

In this exercise, you’ll create the pubs database and then import the document data in the british_pubs.csv file to the british_pubs collection. You’ll then review the collection to verify that the document data has been properly imported into Studio 3T.

Download the british_pubs.csv file here.

To import the documents

If you’ve already created the pubs database and the welsh_pubs collection from the previous section, skip to step 4.

1. Launch Studio 3T and connect to MongoDB Atlas.

You will need a connection string or Uniform Resource Identifier (URI) to connect to MongoDB Atlas. If you haven’t generated a URI, go back to the previous exercise Setting Up MongoDB Atlas to set up an Atlas cluster, and refer to Step 8 of Configuring MongoDB Atlas to get the connection string. Be sure to replace the placeholder in the URI with your actual password.

2. In the Connection Tree, right-click the connection (top-level node) and click Add Database.

3. In the Add Database dialog box, type pubs in the Database Name text box, and then click OK.

Studio 3T adds the pubs database node to the Connection Tree.

4. Right-click the pubs database node and click Import Collections to launch the Import Wizard.

import section

5. On the Choose Import Format page of the Import Wizard, select the CSV option and click OK.

Import format

Studio 3T adds the CSV Import tab to the main window. The tab includes two subtabs, Source options and Target options, as shown in the following figure.

CSV import tab

6. On the Source options tab, select the Import from CSV File option.

7. In the text box beneath the Import from CSV File option, type the full path to the british_pubs.csv file that you downloaded to your system. Alternatively, click the folder icon to the right of the text box and navigate to the file.

After you add the file path, the Source options tab displays a preview of the first 100 documents.

CSV import file

8. Select the File contains header with field names check box so the first row in the .csv file is used for field names.

9. Go to the Target options tab. 

The tab includes options for configuring the document data, as shown in the following figure.

target tab

10. From the Insertion mode drop-down list, select Drop collection first if it already exists.

11. From the Empty fields drop-down list, select Exclude.

This ensures that each document includes only those fields that contain actual values, as opposed to null values. For example, a document won’t include the fax or phone field if the value is null.

12. In the Import options section, clear the check boxes associated with the location.easting and location.northing fields.

Studio 3T removes the fields from the JSON output preview window and excludes the fields from the imported data.

The Target Options tab should now look like this:

Target option removal

13. At the top of the CSV Import tab, click Execute.

Studio 3T creates the british_pubs collection and imports the documents into the collection.

14. Close the CSV Import tab.

If prompted to save changes, click Discard changes.

15. In the Connection Tree, double-click the british_pubs collection node to open the collection in a collection tab.

16. Review the documents in the collection.

Studio 3T should have imported 51,778 documents, each describing a British pub.

17. Leave the british_pubs collection tab open for the next exercise.

In addition to importing files, Studio 3T also lets you import by copying data from a file and pasting it into a collection, as you have seen in Exercise 1 of Working with Document Data.

Previous Lesson
Back to Lesson
Next Topic
  • Course Home Expand All
    Introduction to MongoDB and Studio 3T
    1 Quiz
    Test your skills: Introduction to MongoDB and Studio 3T
    Introduction to MongoDB Atlas
    1 Topic
    Lesson 2, Exercise: Setting up MongoDB Atlas
    Connecting to MongoDB
    1 Topic | 1 Quiz
    Lesson 3, Exercise: Connecting to MongoDB via Studio 3T
    Test your skills: Connecting to MongoDB
    The MongoDB Basics: Databases, Collections & Documents
    7 Topics | 2 Quizzes
    Lesson 4: Understanding MongoDB Documents: Fields & Data Types
    Test your skills: Understanding MongoDB Documents
    Lesson 4: Comparing MongoDB vs SQL Concepts
    Lesson 4, Exercise 1: Creating a collection from a .json file
    Test your skills: Creating a Collection
    Lesson 4, Exercise 2: Reviewing the collection in different views
    Lesson 4, Exercise 3: Using Visual Query Builder to query data
    Lesson 4, Exercise 4: Updating data directly within the collection
    Post-Basics Course Feedback
    Using SQL in MongoDB Aggregation
    3 Topics | 1 Quiz
    Lesson 5, Exercise 1: Running a SQL aggregate query in MongoDB
    Test your skills: Using SQL in MongoDB Aggregation
    Lesson 5, Exercise 2: Exporting a SQL query to the Aggregation Editor
    Lesson 5, Exercise 3: Editing a query in the Aggregation Editor
    Importing and Exporting MongoDB Data
    3 Topics | 1 Quiz
    Lesson 6, Exercise 1: Importing document data from a .csv file
    Lesson 6, Exercise 2: Exporting document data to a .json file
    Lesson 6, Exercise 3: Exporting document data to a new collection
    Test your skills: Importing and Exporting MongoDB Data
    Running MongoDB Queries on the mongo Shell
    4 Topics | 1 Quiz
    Lesson 7: Introducing IntelliShell
    Lesson 7, Exercise 1: Using IntelliShell to load and run a script file
    Lesson 7, Exercise 2: Using IntelliShell’s auto-completion features to write queries
    Lesson 7, Exercise 3: Running queries in IntelliShell and viewing the results
    Test your skills: Running MongoDB Queries on the mongo Shell
    Course Extras
    Return to MongoDB 101: Getting Started
  • Studio 3T

    MongoDB Enterprise Certified Technology PartnerSince 2014, 3T has been helping thousands of MongoDB developers and administrators with their everyday jobs by providing the finest MongoDB tools on the market. We guarantee the best compatibility with current and legacy releases of MongoDB, continue to deliver new features with every new software release, and provide high quality support.

    Find us on FacebookFind us on TwitterFind us on YouTubeFind us on LinkedIn

    Education

    • Free MongoDB Tutorials
    • Connect to MongoDB
    • Connect to MongoDB Atlas
    • Import Data to MongoDB
    • Export MongoDB Data
    • Build Aggregation Queries
    • Query MongoDB with SQL
    • Migrate from SQL to MongoDB

    Resources

    • Feedback and Support
    • Sales Support
    • Knowledge Base
    • FAQ
    • Reports
    • White Papers
    • Testimonials
    • Discounts

    Company

    • About Us
    • Blog
    • Careers
    • Legal
    • Press
    • Privacy Policy
    • EULA

    © 2023 3T Software Labs Ltd. All rights reserved.

    • Privacy Policy
    • Cookie settings
    • Impressum

    We value your privacy

    With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data.

    By clicking “Accept all”, you consent to the storage of cookies and the processing of personal data for these purposes, including any transfers to third countries. By clicking on “Decline all”, you do not give your consent and we will only store cookies that are necessary for our website. You can customize the cookies we store on your device or change your selection at any time - thus also revoking your consent with effect for the future - under “Manage Cookies”, or “Cookie Settings” at the bottom of the page. You can find further information in our Privacy Policy.
    Accept all
    Decline all
    Manage cookies
    ✕

    Privacy Preference Center

    With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes ("analytics and marketing") and to provide you with additional functions (“functional”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data. Please choose for which purposes you wish to give us your consent and store your preferences by clicking on “Accept selected”. You can find further information in our Privacy Policy.

    Accept all cookies

    Manage consent preferences

    Essential cookies are strictly necessary to provide an online service such as our website or a service on our website which you have requested. The website or service will not work without them.

    Performance cookies allow us to collect information such as number of visits and sources of traffic. This information is used in aggregate form to help us understand how our websites are being used, allowing us to improve both our website’s performance and your experience.

    Google Analytics

    Google Ads

    Bing Ads

    Facebook

    LinkedIn

    Quora

    Hotjar

    Reddit

    Functional cookies collect information about your preferences and choices and make using the website a lot easier and more relevant. Without these cookies, some of the site functionality may not work as intended.

    HubSpot

    Social media cookies are cookies used to share user behaviour information with a third-party social media platform. They may consequently effect how social media sites present you with information in the future.

    Accept selected