Problem while exporting mongoDB Collection - mongodb

I am using MongoDB version 1.6.5
One of my collection has 973525 records.
when I try to export this collection mongodb exports only 101 records.
I can't figure out the problem .
any one knows the solution for it.

This sounds like corruption. If your server has not shutdown cleanly that could be the cause. Have you had system crashes where you didn't do a repair?
You can try to do a dump with mongodump --dbpath if you shut down the server first.
Note: MongoExport/Import will not be able to restore all the data since json can't represent all possible data types.

Related

Mongodb --repair throws a core dump - how do I recover the raw data?

We have a stand-alone MongoDB instance running the latest release via docker.
We had a severe crash yesterday, when one of analysts dropped a database while a separate process attempted to insert a document into one of the collections of the database. Presumably this led to a race condition, but regardless, MongoDB crashed.
We restarted MongoDB, but it kept crashing. We then ran the --repair command and MongoDB threw a core dump.
I can’t find any actual documentation around the --repair command, is it possible to rebuild the database without building the indexes? We just need to recover the data.
My question is how do I recover the raw data from the WiredTiger files:
collection-138-3885477232820226262.wt
Is this just BSON? Is there a way to extract the raw data so I can just re-insert it into a fresh mongodb instance?
thanks!

Can I use mongdb data in my v4.4.5 database that was exported from v3.6.3?

I have a mongodb database with version 3.6.3. I have another mongodb database (on another machine) using version 4.4.5 with no documents in it. I want to put the data from the v3.6.3 into the v4.4.5 database. Can I safetly do this using mongoexport and then mongoimport or do I need to perform more steps?
Yes, mongoexport writes the documents out to a JSON file, and mongoimport can read that file and insert the documents to the new database.
These will transfer only the documents, but not index information. You many want to consider mongodump/mongorestore if you also need to move indexes.

How to avoid auto-updating of MongoDB ObjectIds after restoring the dump using mongorestore command?

I am trying to restore my database dump using mongorestore command. And got to know that some ObjectIds are updating automatically after restoring and am facing data dependency issues with that. Does ObjectIds updates itself while restoring? If yes, is there any alternative to stop that issue?

Mongodump not dumping all records

I am using mongodump(version 2.4.14) to create a db backup that I restore on another system using mongorestore(version 2.4.14) but all the records are not being dumped and restored in the target mongo(2.4.14) instance.
I have tried:
Restoring the db to two separate instances of mongo and the problem persists on both.
Mongoexport with queries - Mongoexport document export count and db.collection.count does not match.
While trying to debug this, I came across this link in which others came across the same problem but no solution for the problem is mentioned.
I am looking for a any help in regards to finding out what the problem might be, how can I debug this further.
Update - Mongoexport/import a particular query response and importing it to a freshly created database works fine. The issue arises only when importing to existing db.

MongoDB migration

Hello I have an ubuntu 14.04 server that is running mongodb 2.4.14. I need to move the mongo instance to a new server. I have installed mongo 3.4.2 on the new server and need to move the databases over. I am pretty new with mongo. I have 2 databases that are pretty big but when I do a mongo dump the file is nowhere near the site of the databases that mongo is showing.I cannot figure out how to get mongoexport to work. What would be the best way to move those databases? If possible can we just export the data from mongo and then import it?
You'll need to give more information on your issue with mongodump and what mongodump parameters you were using.
Since you are doing a migration, you'll want to use mongodump and not mongoexport. mongoexport only outputs a JSON/CSV format of a collection. Because of this, mongoexport cannot retain certain datatypes that exist in BSON and thus MongoDB does not suggest that anyone uses mongoexport for full backups; this consideration is listed on mongo's site.
mongodump will be able to accurately create a backup of your database/collection that mongorestore will be able to restore that dump to your new server.
If you haven't already, check out Back Up and Restore with MongoDB Tools