Reputation: 11
In sql we can new column by writing query: "ALTER TABLE Customers ADD Email varchar(255)"
In nodejs, How can we add new column/key in mongodb, without directly changing the existing Schema?
Upvotes: 0
Views: 1543
Reputation: 15276
Just use $set to set the new field and insert value.
db.collection.update({}, { $set: { "Email": "newValue" } }, { multi: true })
multi: true is for updating multiple documents.
multi: true
Upvotes: 1