In more simple words, we can define it as an open source database server product which is used for document oriented storage. The above namespace translation is equivalent to use of the -db option, and is the correct namespace manipulation setup to use as we are not attempting to filter what is being restored.MongoDB is known as a document oriented database server. Some may also point at the -db argument to mongorestore, however this, too, is deprecated and triggers a warning against use on non-BSON folder backups with a completely erroneous suggestion to " use -nsInclude instead". nsFrom 'byzmcbehoomrfjcs9vlj.*' -nsTo 'rita.*' Mongorestore -archive=backup.agz -gzip -drop \ ( Documentation.) Continuing with my above hypothetical (and extremely unreadable) example, to restore to a more sensical name, I invoke: Import your data, supplying -nsFrom and -nsTo arguments. For example, on one of my datasets, I have a collection with the namespace byzmcbehoomrfjcs9vlj.Analytics - that prefix ( actually the database name) will be needed in the next step. ?Įquivalent behavior involves mongodump and mongorestore in a bit of a dance:Įxport your data, making note of the "namespaces" in use. I've updated SERVER-701 with my notes and incredulity. Other answers point at copyDatabase, which is no longer an option as the functionality has been removed in 4.0. The currently accepted answer at time of writing is factually correct and offers some interesting background detail as to the excuse upstream, but offers no suggestions for replicating the behavior. There is no mechanism to re-name databases. Depending on the size of the collection, this RenameCollection copies all documents from the source collection to If the target database differs from the source database, RenameCollection simply changes the namespace. If the target database is the same as the source database, RenameCollection has different performance implications depending on the target namespace. To do it offline, it would require re-writing every single database file to accommodate the new name, and at that point it would be as slow as the current "copydb" command.Īlthough Mongodb does not provide the rename Database command, it provides the r ename Collection command, which not only modifies the collection name, but also modifies the database name. There would be absolutely no way to do this on a live system.
#Mongodb with robomongo tutorial full#
For replica sets the above would need to be done on every replica node, plus on each node every single oplog entry that refers this database would have to be somehow invalidated or rewritten, and then if it's a sharded cluster, one also needs to add these changes to every shard if the DB is sharded, plus the config servers have all the shard metadata in terms of namespaces with their full names. This is just to accomplish a rename of a single database in a standalone mongod instance. contents of system.namespaces and system.indexes (or their equivalents in the future).internal unique names of each collection and index.every single numbered file for the collection.In MMAPv1 files, the namespace (e.g.: llection) that describes every single collection and index includes the database name, so to rename a set of database files, every single namespace string would have to be rewritten. Unfortunately, this is not an simple feature for us to implement due to the way that database metadata is stored in the original (default) storage engine.