[DOCS-15555] [TOOLS] mongorestore fails to copy/clone an existing database to a new one Created: 22/Aug/22 Updated: 22/Jan/24 |
|
| Status: | Backlog |
| Project: | Documentation |
| Component/s: | tools |
| Affects Version/s: | None |
| Fix Version/s: | None |
| Type: | Task | Priority: | Major - P3 |
| Reporter: | Anonymous User | Assignee: | Unassigned |
| Resolution: | Unresolved | Votes: | 0 |
| Labels: | backlog, request | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Participants: | |||||||||
| Days since reply: | 1 year, 24 weeks, 2 days ago | ||||||||
| Description |
|
The documentation on mongodump and mongorestore should clearly specify that at the exact place how quotes should be used (or should they not be used at all) while passing the values of --nsFrom and --nsTo arguments in the mongorestore command. While using single quotes (as written in the document) executes mongorestore properly in a Mac computer, but it fails in doing so in a Windows PC. To run the same in a Windows PC successfully, the values for --nsFrom and --nsTo need to be passed with either double quotes or no quotes at all. The correct procedure should be updated in the documentation properly. Engineering Description Problem Statement/RationaleIn my Windows 10 PC using MongoDB 5.0.7 Community edition, while trying to copy an existing database to a new one using mongodump and mongorestore commands as mentioned in the documentation of MongoDB here, although mongodump is executing and creating the dump file properly, the mongorestore command fails every time generating a duplicate key error.
Surprisingly, it seems to restore the collection Products in mydb database instead of newdb. As mydb already contains the products collection having rows of documents with unique ids, it’s creating a clash generating the duplicate key error. Somehow, mongo seems to be ignoring the new database argument altogether. Steps to Reproduce
Instead of copying the contents of mydb database to a new one named newdb, MongoDB is generating a duplicate key error.
Additional NotesWhile delving deep into the problem, I found the reason. The problem lies in using single quotes while passing the values of -
Surprisingly, the mongorestore command works perfectly with single quotes while passing the values of --nsFrom and --nsTo arguments in a Mac computer, making it even more confusing for Windows users.
This seems to be a bug in MongoDB Server system or its syntax and needs to be rectified in the next update. The same needs to be updated in the documentation also. If there's some OS-specific syntax issue involved, the documentation on mongodump and mongorestore should clearly specify that at the exact place here []|https://www.mongodb.com/docs/database-tools/mongodump/?&_ga=2.234397854.1469458796.1649914316-1657763159.1648793391#copy-clone-a-database].] Otherwise, it ends up being extremely puzzling for readers, especially beginners, who would definitely try to implement the code in the documentation for testing and development. |