Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As noted in the other stack overflow question mentioned above, MongoDB doesn't actually have the ability to rename a database. You can however, copy then delete but be aware this will cause indexes to be rebuilt. You wouldn't want to do this for a large data set.</p> <p>The mongo-ruby-driver (as well as most 10gen drivers) has the ability to execute any <a href="http://docs.mongodb.org/manual/reference/commands/" rel="nofollow">MongoDB command</a> through a call to the <a href="http://api.mongodb.org/ruby/current/Mongo/DB.html#command-instance_method" rel="nofollow">DB#command</a> method on any DB object instance. </p> <p>In the Ruby driver you would do the following:</p> <pre><code>require 'mongo' client = Mongo::MongoClient.new db = client.db('admin') db.command({:copydb =&gt; 1, :fromdb =&gt; oldname, :todb =&gt; newname}) client.drop_database(oldname) </code></pre> <p>Update: In newer versions of MongoDB there is a JS shell helper for db.rename() which does exactly what the ruby code above does.</p> <pre><code>function (newName) { if(newName == this.getName() || newName.length === 0) return; this.copyDatabase(this.getName(), newName, "localhost"); this.dropDatabase(); db = this.getSiblingDB(newName); } </code></pre> <p>In addition to that, there is the following feature request ticket for making db.rename() a first class command. Please feel free to upvote this feature.</p> <p><a href="https://jira.mongodb.org/browse/SERVER-701" rel="nofollow">https://jira.mongodb.org/browse/SERVER-701</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload