Posts

How to rename a field in MongoDB using MongoChef

Every now and then you may need to change the name of a field within your MongoDB documents. Whether you need to do it for a single document, or perhaps for multiple documents, this task can be easily accomplished with only a few steps from within the MongoChef app.

Renaming A Field Name In A Single Document Within MongoDB

The simplest of these tasks is changing a field name in single document. See the steps below:

  1. Open the document in which the field to be renamed is located
  2. Double click on the field name (In this case “dob”)
  3. You will now have the option to type the new field name into this space
  4. Once you press “Enter” the new field name will be saved

MongoChef Support, MongoChef, MongoDB

Renaming A Field Name Within Documents Matching A Query

Should you wish to change all documents matching a particular query then this can also be easily achieved in just a few steps. In this example we are changing the “dob” field in all documents relating to customers with the last name “Miller”. See below:

  1. Type in your query: {last:"Miller"} – and hit “Enter”
  2. Open one of the documents resulting from the query search
  3. Find the field that you would like to rename (“dob”) and right click it.
  4. Select “Rename Field”
  5. Type in the new field name (“date_of_birth”) and hit“Enter”
  6. Select “Documents matching query criteria” from the dropdown box
  7. Click “Enter”
  8. Now every document within this query will have the field name “date_of_birth” in place of “dob”

MongoChef Support, MongoChef, MongoDB

Renaming A Field Name In All Documents Within A Collection

Finally, to rename a field in all documents within a collection follow the steps below (identical to the steps above apart from no. 4):

  1. Find the field that you would like to rename (again “dob”) and right click it
  2. Select “Rename Field”
  3. Type in the new field name (“date_of_birth”) and hit “Enter”
  4. Select “All documents in collection” from the dropdown box
  5. Click “Rename”
  6. Now every document in the entire collection will have the field name “date_of_birth” in place of “dob”

MongoChef Support, MongoChef, MongoDB

 

That’s it for this post, but if you still have a little time, please check out the other very useful features of MongoChef!

Limit the initial number of documents loaded when opening a collection view

By default, 3T MongoChef for MongoDB loads the first 50 documents of a collection (i.e. dbCursor.find({}).limit(50)) when first opening a collection view.  As MongoDB documents can be up to 16MB in size, this can amount to serious traffic in some circumstances.

With version 1.7.2, we are now introducing a convenient way of limiting that initial number of documents manually. In the MongoChef’s preferences, you’ll now find a “Collection View” tab. Here, you can globally define the initial number of documents to load whenever a collection view is opened.

MongoChef: Limit number of documents to load

For more fine-grained control, for example for collections with exceptionally large documents, 3T MongoChef now lets you specify the initial number of documents loaded in an ad-hoc manner as well. Simply right-click on the collection you would like to open in the open-connections tree in the left pane, and you will be given the option to “Open Collection View…”. This will first prompt you to enter the number of documents you would like to load initially.

MongoChef: Limit the number of documents to load (ad-hoc mode)