13

I have a schema that looks like

name: 
value:
pattern:
XUknown:

I have 2 million documents in this collection.

Want
- I want to rename the column name XUknown to XString, so that the schema looks like

name: 
value:
pattern:
XString:  

How can I achieve this?

Thank you

daydreamer
  • 80,741
  • 175
  • 429
  • 691

2 Answers2

31

You can use a $rename modifier.

db.collection.update({}, {$rename: {'XUknown': 'XString'}}, false, true);

You might also refresh your knowledge of update().

mythicalcoder
  • 2,847
  • 30
  • 42
Sergio Tulentsev
  • 219,187
  • 42
  • 361
  • 354
6

You can rename all the document by specify "Multi true" applicable to all the documents in the collection.

db.collection.update({}, {$rename: {'XUknown': 'XString'}}, {multi:true});
Sergio Tulentsev
  • 219,187
  • 42
  • 361
  • 354
Rizwan
  • 71
  • 1
  • 1