2

Like most folks coming from a Relational background, we stuck with rather large column names. Now the code + App is coded & tested. But Mongo best practices note that key names should be short as every column name is stored with-in each document. To complicate things further, we are using the Mongo drivers directly, without any mapping layer like Morphia etc.

Let me rephrase: Even if I use $rename to rename the columns, the client APP is still using the longer names. Then I need to do some kind of JSON Transformation, on each document going out & coming in: on the way out {U: "", C:""} will need to become {Updated:"", Created: ""}. Vice-versa on the way-in.

Community
  • 1
  • 1
user2849678
  • 613
  • 7
  • 15
  • Are you asking about updating the field names in your mongo collections are are you asking how to update your code? Can you edit your question to be more clear on this. – Neil Lunn Mar 03 '14 at 07:02
  • 1
    It's not a best practice that is just some guys opinion. You should really evaluate the situation and understand if you actually need this. I should mention that the reason you state is not the reason why field names take so much space. The reason is that there isnot compression of field names yet, that will soon hopefully change though – Sammaye Mar 03 '14 at 08:03

1 Answers1

1

You can rename keys one by one in all records with a multi update using the $rename operator, which updates the name of a field:

db.collection.update({}, {$rename:{"foo":"bar"}}, false, true);

The options are false for upsert, and true for multi-update.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404