Orelsanpls
Orelsanpls

Reputation: 23495

mongodb terminal - $push/$pull - SyntaxError: invalid property id @(shell)

I'm trying to add and update a simple data, what is wrong with my request ?

I'm using the website https://www.jdoodle.com/online-mongodb-terminal

enter image description here


#1

db.Vendor.find()


#2

 db.Vendor.insert({
    employee: [ 
       ObjectId('fffffa000000000000000002'),
       ObjectId('fffffa000000000000000003')
    ]
 });

#3

db.Vendor.update({
  "employee": ObjectId("fffffa000000000000000002")
}, {
  $push: {
     "employee" : ObjectId("fffffa000000000000000004")
  }
});

Upvotes: 1

Views: 707

Answers (1)

Alex Blex
Alex Blex

Reputation: 37028

It's jdoodle terminal specific I guess. The document should be a valid json, not just a js object as in the cli mongo shell.

db.Vendor.update({
  "employee": ObjectId("fffffa000000000000000002")
}, {
  "$push": {
     "employee" : ObjectId("fffffa000000000000000004")
  }
});

does the job.

Upvotes: 2

Related Questions