title: How to apply a user defined function (UDF) to a document field in mongoDb?
body: <p>Lets say you have the following schema</p>
  
  <pre><code>employee( firstname, lastname, dept)
  </code></pre>
  
  <p>Say we want the <code>lastname</code> to be uppercase for all the rows in the table (the uppercase function might be a built-in function in the DBMS, but lets assume it's a UDF)</p>
  
  <p>In SQL we would have done the following</p>
  
  <pre><code>Select firstname, toUpper(lastname) as lastname, dept
  From employees 
  </code></pre>
  
  <p>What is the equivalent in mangoDB ? Knowing that we have a document <code>employees</code> which contains the following JSONs:</p>
  
  <pre><code>...
  { "firstname": "jhon", "lastname": "doe", "dept": "marketing"}
  ...
  { "firstname": "jean", "lastname": "dupont", "dept": "sales"}
  ...
  </code></pre>
  
  <p>The goal is to directly obtain the changed data using mongoDB query API, without writing extra JS code to get the job done.</p>
  
  <p>I Know how to save/import a UDF in <a href="https://docs.mongodb.com/manual/tutorial/store-javascript-function-on-server/" rel="nofollow noreferrer">MongoDB</a>. What I don't know is how to apply it to a result:</p>
  
  <pre><code>db.employees.find().apply_my_udf(....)
  </code></pre>