0

I am using Loopback 3 and mongoDB

I add new field with default value in json model

  {
    "name": "myModel",
    "options": {
        "mongodb": {
          "collection": "MyModel"
        }
    },
    "mixins": {
       "ShareApi": {
        "allow": ["findById"]
      }
    },
    "properties": {
      "name": {
        "type": "string",
        "description": "name"
      },
      "newField": {
        "type": "boolean",
        "default": false
      }
    }
  }

However, this just work for new documents. How to old documents are updated with newfield

Vu Le Anh
  • 708
  • 2
  • 8
  • 21

1 Answers1

0

If you want to update all documents then use updateAll query of loopback:

myModel.updateAll({}, { newField: true }, function (err, affected) { })
                            
Surbhi Rawat
  • 1
  • 1
  • 1