Search code examples
azureazure-cosmosdbnode-modulesuser-defined-functions

Executing UDF ( User Defined function ) containing a Node module in Cosmos Db


I have created a UDF function to process some content based on dates in Azure cosmos database. The function looks like below

  
  function userDefinedFunction(array,dateString){
    var moment = require('moment');
    const startDate = moment(dateString);
    const endDate = moment(dateString).add(1,'days');
    // filter the array by the dates and return a value
   
  }

When the above UDF is used inside a query the following error message is thrown .

Encountered exception while executing Javascript. Exception = ReferenceError: 'require' is not defined

This error is seemed to be an error orginating from incorrect import of the moment node module.

i have already tried checking on the microsoft offcial docs about the UDFs and using of node module inside UDF.

I tried surfing through the internet about this issue, but both the methods did not provide me with satisfactory answer.

so i would like to know how to import a node module and use it inside an UDF function . Thanks a lot in advance .


Solution

  • Importing modules is not supported for any of the service-side features including stored procedures, triggers and user-defined functions.

    This is not currently documented. Will ask for this to be updated.