Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to see mongodb data from .ns files

Tags:

php

mongodb

I have just explored the mongodb. When ever i store the data using mongo. It will store that data in *.ns file.

So how can I see data stored from the .NS file?

When I had tried to open this file in notepad++, it shows lots of NULL.

Is there any other way to check the data stored in mobgodb.?

like image 885
Avinash Avatar asked Feb 23 '23 12:02

Avinash


1 Answers

I believe the data itself is not saved in the NS files, but on files with extension .0,.1 etc. with same name. Those files are not designed to be read with text editors.

Probably the easiest way is to start a mongod process by pointing to the folder where you have the files (mongod --dbpath /path/to/your/files/). Then you can just use mongo shell to explore the contents.

You do get some cleartext portions of the datafiles, but mostly it's unreadable with typical text-editor.

dbname.0 is the pre-allocated initial datafile , which starts with 64MB

dbname.ns is for book-keeping. ns stands for namespace. The default limit for the 16MB .ns file supports 24,000 namespaces (collections + indexes) (see: --nssize parameter)

whenever MongoDB grows beyond the size of the last dbname.x file, it allocates a new data file with twice the size, up to size 2GB. Once the file size reaches 2GB, each successive file is also 2GB.

like image 160
Lycha Avatar answered Feb 25 '23 16:02

Lycha