How to change the type of a field?

后端 未结 13 2325
北荒
北荒 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:33

    To convert int32 to string in mongo without creating an array just add "" to your number :-)

    db.foo.find( { 'mynum' : { $type : 16 } } ).forEach( function (x) {   
      x.mynum = x.mynum + ""; // convert int32 to string
      db.foo.save(x);
    });
    

提交回复
热议问题