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
  • 87,243
  • 191
  • 450
  • 722

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
  • 3,143
  • 1
  • 32
  • 42
Sergio Tulentsev
  • 226,338
  • 43
  • 373
  • 367
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
  • 226,338
  • 43
  • 373
  • 367
Rizwan
  • 71
  • 1
  • 1