Mongoimport command info

Although, I have passed all the labs but I am having doubt in the last one i.e. where will my data is imported( on which file/directory) as far as mongoimport command is concerned. Please note that I haven’t used the drop parameter while importing.

Hi @Raghvendra_12694,

The directory path that you have specified in the dbpath while starting the mongod instance.

--drop parameter drops any existing collection from the database before importing data from the input. It doesn’t matter if the collection was empty.

In addition to that, you can also refer this lecture > Chapter 1: The Mongod File Structure to know more about the file structure.

Hope it helps!

Please let me know if you have any other questions.

Thanks,
Shubham Ranjan
Curriculum Services Engineer

Are you trying to say the default DB path or the one at that point of time in config file i.e. /var/mongodb/db ?

What is specified in the configuration file or command line overrides any defaults.

I haven’t specified the file name where the data is stored .So how to find it

Can you share the exact command and options you used?

Hi @Raghvendra_12694,

When you don’t specify it then it automatically uses this default directory which is /data/db. This is encoded in the binaries.

In the default mongod.conf file it is /var/lib/mongodb.

These are the defaults.

But as you will progress in this course and write your own configuration file, you will be specifying different dbPath.

Just a heads up : You can’t read the data though because it’s in the Wiredtiger format.

Hope it helps!

Thanks,
Shubham Ranjan
Curriculum Services Engineer

I can see many files in the var/lib/mongodb/db directory but don’t know which one is the collection file where data is stored… I have used the following command-:
mongoimport --port 27000 --host localhost -u m103-application-user -p m103-application-pass --authenticationDatabase admin -d applicationData -c products /dataset/products.json

Any reason why you want to know the collection file where data is stored?

Collection files using the WiredTiger engine will look like

rw------- 1 mongodb daemon 16384 Feb  9  2019 collection-0-6994620683102372315.wt
-rw------- 1 mongodb daemon 36864 Feb  9  2019 collection-2-6994620683102372315.wt
-rw------- 1 mongodb daemon  4096 Feb  9  2019 collection-4-6994620683102372315.wt

But I would not touch those files.

Because I am curious to know as the old saying goes “A little knowledge is a dangerous thing”. Anyways which one has that collection and how to read it.

It looks like you started the mongod instance using a config file and you specified /var/mongodb/db as the dbpath. Is that correct? If you did, this is where all the data files (including collection data) is going to be stored.

mongoimport does not dictate where the data is going to be stored, it only imports. In your case, the dbpath dictates where all data files are stored.

That’s what @Shubham_Ranjan and @steevej-1495 have been explaining.

You may guess which one it is looking at the sizes and with db.stats(). Or just after a call to createCollection() you look at which files are created.

Because MongoDB reads them. They are BSON files managed via the WiredTiger engine. If I remember correctly with WiredTiger there is a way to specify different directories for different collections and indexes so that collections are stored in different disk partitions. But I do not recall the option.

:arrow_down:

Adding to @steevej-1495’s last comment, look up …
directoryPerDB and directoryForIndexes

Hi @Raghvendra_12694,

Why don’t you connect to the mongod instance from the mongo shell/ Compass and have a look at the data ?