0

I am trying to add a field to all documents in the database, but I am not sure how to do that. Here is my database

      const db = client.schema

How would I update all documents and add a field called tiks (number) in it?

Bob joe12
  • 103
  • 22

1 Answers1

4
db.yourCollection.update(
  {},
  { $set: {"newField": 1} },
  false,
  true
)

Parameters

  1. Collection to update since you want all {}
  2. Field to set
  3. Upsert - only add when it is not there hence false
  4. Multi - update multiple documents if matches to query hence true
Janitha Tennakoon
  • 856
  • 11
  • 40