How to change the type of a field?

后端 未结 13 2326
北荒
北荒 2020-11-22 15:10

I am trying to change the type of a field from within the mongo shell.

I am doing this...

db.meta.update(
  {\'fields.properties.default\': { $type :         


        
13条回答
  •  广开言路
    2020-11-22 15:32

    You can easily convert the string data type to numerical data type.
    Don't forget to change collectionName & FieldName.
    for ex : CollectionNmae : Users & FieldName : Contactno.
    

    Try this query..

    db.collectionName.find().forEach( function (x) {
    x.FieldName = parseInt(x.FieldName);
    db.collectionName.save(x);
    });
    

提交回复
热议问题