Importing Data and referencing Object ID resulting in blank screen

Dear all,
I am totally new to MongoDB and currently investigating to what extend I can make use of the database structure while I have mostly been working with RDBMS until now.

First try was an import of an example data set (CSV) from Craft Beers Dataset | Kaggle via the MongoDB Compass Community edition under Windows.

The data set consists of two CSV files to import. So I created a new database with two collections trying to upload the CSV files to one collection each.

The CSV already contains IDs which is why I selected at the importing dialog at the first selectable column “ObjectID” instead of “String”. Unfortunately after confirming the selection with hitting the import button, the screen stays totally blank. Just the top menu bar remains visible but nothing else. This behaviour happens every time again while when keeping the columns data type to “String” everything works fine.

Can someone please explain this behaviour and let me please know why the data cannot be linked to each other?

Cheers,
Anton

Hello @Anton_M, welcome to the community.

The CSV already contains IDs which is why I selected at the importing dialog at the first selectable column “ObjectID” instead of “String”. Unfortunately after confirming the selection with hitting the import button, the screen stays totally blank …

The id field in the CSV is of data type string, and not ObjectId - importing a string as ObjectId is not allowed. I think, thats why the GUI went blank. An appropriate message would have been useful.

When you import with CSV’s id field as string data type it imports fine. The imported document also has a field named _id with an auto-generated unique value of type ObjectId (e.g., "_id" : ObjectId("5f28e55e578bbec021496e67")).

Your imported document is probably like this:

{ "_id" : ObjectId("5f28e55e578bbec021496e67"), "id" : 1436, "name" : "Pub Beer" }

If you are looking to make the CSV file’s id field as _id in the collection’s document, you can try this. First, id values must be unique. Second, it will be of type string. The sample imported document might look like this:

{ "_id" : "14363", "name" : "Pubs Beer" }

For this to happen, you just have to change the CSV’s id field name to _id, and then do the import.


You can also use the mongoimport command-line MongoDB utility program - to import data from CSV files into the MongoDB collections.

Please do include a sample of CSV data as text within the post. Also, mention the versions of the MongoDB server and the Compass.

You can try the menu options View → Reload Data (or Reload) for the screen to appear again.