Run mongo query in shell

I have a little problem when trying this in shell script ( works fine directly on mongo database shell):

mongo jenkinsdb<< EOF


ids_to_exclude = db.history.find({projectId: $object_id._id.str}, 
{_id:1}).sort({"_id":-1}).limit(2).toArray()
var array = new Array()
ids_to_exclude.forEach(function(myDoc){array.push(myDoc._id);})
array
db.getCollection('history').updateMany({ _id:{$nin:array}},{$set:{backupPath:undefined}})

exit
EOF

I get “uncaught exception: SyntaxError: expected property name, got ‘:’ :
@(shell):1:46” i think the problem is in “db.getCollection …” command.

Answered you in the other thread.

1 Like