-1

I'm trying to expand a MongoDB row with a new column/field with a new column named key_reference, which doesn't seem to work. This is my Query in Robo 3T (similar to MySQL Workbench for MySQL or PgAdmin for Postgres)

doc1=db.getCollection('store.files').find({ _id : ObjectId("5ad5a07ccbce1d0873264ee6")});

doc1({$addFileds:{'key_reference':'1234'}});

What do I miss?

RonPringadi
  • 1,294
  • 1
  • 19
  • 44
  • You have to use update query for it `db.getCollection('store.files').findOneAndUpdate({ _id : ObjectId("5ad5a07ccbce1d0873264ee6")},{$set:{key_reference:'12345'}}); ` – Ashh Mar 28 '19 at 18:03

1 Answers1

1

$addFields is an Aggregation Pipeline Stage which means that it can be used only with .aggregate() method, try:

db.getCollection('store.files').aggregate([
    { $match: { _id : ObjectId("5ad5a07ccbce1d0873264ee6")} },
    { $addFields:{'key_reference':'1234'}}
]);
mickl
  • 48,568
  • 9
  • 60
  • 89