View definition of custom function made

I made a function as per the function in on Demand Materialized View topic in MongoDB doc.

My Function is

 updateMonthlySales_05 = function(startDate) {
   db.bakesales.aggregate( [
      { $match: { date: { $gte: new Date("2018-05-01") } } },
      { $group: { _id: { $dateToString: { format: "%Y-%m", date: "$date" } }, sales_quantity: { $sum: "$quantity"}, sales_amount: { $sum: "$amount" } } },
      { $merge: { into: "monthlybakesales_06", whenMatched: "replace", whenNotMatched: "insert" } }
   ] );

and I call it by
updateMonthlySales_05 (new ISODate(“1970-01-01”));

Now, I want to find where my function (updateMonthlySales_05 ) is stored and what was its definition. How can I look for it in future perspective?

Hello @MWD_Wajih_N_A, welcome to the MongoDB Community forum.

The function updateMonthlySales_05 is created in the mongo shell, and it is available in that environment, until you exit the shell. It is just a JavaScript function. The example used the function to demonstrate the On-Demand Materialized Views.

But, you can execute a JavaScript file (which is. already created) from the shell. While editing a function you can also use an external editor by configuring the mongo shell.


I really appreciate you taking time out. Now, as you can see, I am using Robo to create this function but its not getting saved and hence is not getting queried either.


Hello @MWD_Wajih_N_A, I don’t use a Robo tool , so I don’t know how it works (perhaps the tool comes with a Help or User Guide and there should be a link or a button or a menu option on the GUI itself).

1 Like