-
Type: Bug
-
Resolution: Fixed
-
Priority: Critical - P2
-
Affects Version/s: 0.7.7
-
Component/s: Aggregation pipeline
-
None
-
2
-
Iteration Vegetable
-
Not Needed
[the following works perfectly in the [legacy] Mongo Shell 4.4 for MongoDB 4.4]
mongosh throws an error when attempting to create a view based on agg pipeline which uses $function operator. The view can't be created as a result.
Docs for $function: https://docs.mongodb.com/manual/reference/operator/aggregation/function/
(issue may also affect $accumulator https://docs.mongodb.com/manual/reference/operator/aggregation/accumulator/ too - I've not tested that).
Steps to reproduce (using mongosh 0.7.7 connected to a MongoDB 4.4+ DB running on localhost):
db.persons.drop(); db.persons.insertOne({ 'name': 'John Smith', }); db.persons.find(); var pipeline = [ {'$set': { 'name_md5': {'$function': {'lang': 'js', 'args': ['$name'], 'body': function(val) { return hex_md5(val); } }}, }}, ]; db.persons.aggregate(pipeline); db.persons_view.drop(); db.createView('persons_view', 'persons', pipeline); // ERROR!!!! db.persons_view.find();
When you run this in mongosh, the createView() command above (penultimate line of code) results in following mongosh error being displayed:
MongoError: Invalid pipeline for view testdata.persons_view :: caused by :: Invalid $set :: caused by :: The body function must be specified.
It seams somehow that mongosh is losing the 'body' field from the $function declared in the pipeline.