How to change the type of a field?

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

    demo change type of field mid from string to mongo objectId using mongoose

     Post.find({}, {mid: 1,_id:1}).exec(function (err, doc) {
                 doc.map((item, key) => {
                    Post.findByIdAndUpdate({_id:item._id},{$set:{mid: mongoose.Types.ObjectId(item.mid)}}).exec((err,res)=>{
                        if(err) throw err;
                        reply(res);
                    });
                });
            });
    

    Mongo ObjectId is just another example of such styles as

    Number, string, boolean that hope the answer will help someone else.

提交回复
热议问题