Knowledge base · Studio 3T Desktop IDE

The quickest way to change a field type in MongoDB

By Kathryn Vargas, Kirsty Burgess · Updated

When exploring MongoDB collections or analyzing schemas, you may stumble upon incorrect or wrong field types.

Maybe it’s just a mistake on a single document, or maybe it’s across all documents in your collection and you need to bulk-edit. Studio 3T allows you to quickly make these changes to MongoDB field types in just a few clicks, without needing to know the syntax for the $set operator.

Change the field type in a single document

In this example, we want to change the dob field type from string to date – but only in a single document.

Right-click on the field you want to edit and select Field > Edit Value / Type.

Edit a MongoDB field type

Under Type, select the new field type (for example, date).

Then, in Set this field in, select Current document only.

Change MongoDB field type from string to date

Click Set Value.

Get familiar with the BSON types supported by MongoDB.

Bulk-edit a field type in all documents in a collection

In this example, we want to change the transactions field type which stores a customer’s total number of transactions from string to Int32 (32-bit integer) – but for all documents in the collection.

Right-click on any transactions value in the collection and select Field > Edit Value / Type.

In the Edit Value dialog, under Type, select Int32.

Then, in Set this field in, select All documents in collection.

Next, make sure to select Only change type (“Convert”).

Bulk-edit field types in all documents in a MongoDB collection

We’re changing only field types – not values – so make sure to select “Only change type”. Selecting “Always change value” updates the values across all documents, which we don’t want to do here.

Click Set Value.

Other field type editing options

Apart from editing a field type in the current MongoDB document or all documents, you can also change the field type in:

  • documents matching query criteria (if you’re new to Studio 3T, you can set matching criteria for queries in Visual Query Builder)
  • documents matching query criteria that have or don’t have a particular field
  • all documents in collection that have or don’t have a particular field

Follow the same steps as mentioned above – and make sure to select Only change type when editing the documents.

Save time on other common MongoDB tasks with Studio 3T:

With your consent, we and third-party providers use cookies and similar technologies on our website to analyse your use of our site for market research or advertising purposes, including personalized advertising (“performance”), to provide you with additional functions (“functional”), and to show content from social media platforms, such as embedded videos (“social media”). This may result in the creation of pseudonymous usage profiles and the transfer of personal data to third countries, including the USA, which may have no adequate level of protection for the processing of personal data. Please choose for which purposes you wish to give us your consent and store your preferences by clicking on “Accept selected”. You can find further information in section 9 of our Privacy Policy.

Manage consent preferences