Fernando Mascarenhas
Fernando Mascarenhas

Reputation: 45

mongorestore returning less documents with no erro

I am running a mongodump followed by a mongorestore and in 2 out of 12 collections the numbers of documents restored are way less than the number of documents on the backup. The thing is there are no errors.

Bellow is the output fot the 2 collections on the dump

2020-01-22T10:16:26.961-0300 done dumping montele.usuario (960 documents)

2020-01-22T10:29:35.268-0300 done dumping montele.negocio (86851 documents)

And now the output for the restore

2020-01-22T10:35:21.121-0300 finished restoring montele.usuario (31 documents, 0 failures) 2020-01-22T10:37:29.974-0300 finished restoring montele.negocio (26120 documents, 0 failures)

Interesting enough .... if I run the mongorestore again without dropping the db this happens:

2020-01-22T11:30:41.914-0300 finished restoring montele.negocio (0 documents, 86851 failures)

With the failure code being:

E11000 duplicate key error collection: montele.negocio index: id dup key:

After looking for a solution and having no success, I hope someone can shine a light and point me in right direction.

Upvotes: 0

Views: 295

Answers (1)

CaioT
CaioT

Reputation: 2211

What MongoDB version are you using? Are you restoring the dump into an empty collection or does it already have data in it?

From mongoDB documentation:

mongorestore can create a new database or add data to an existing database. However, mongorestore performs inserts only and does not perform updates. That is, if restoring documents to an existing database and collection and existing documents have the same value _id field as the to-be-restored documents, mongorestore will not overwrite those documents.

Source: https://docs.mongodb.com/manual/reference/program/mongorestore/

Upvotes: 0

Related Questions