Runtine error when attemptin to save atlas function


I’m attempting to save the following function which runs successfully in the console but produces the message: Changes could not be saved. Please resolve the errors above → runtime error during function validation. I have insatlled the dependenceies. Can anyone exlain the error (and how to resolve it).

import { getWeek } from 'date-fns'
import { addWeeks } from 'date-fns'
import { getYear } from 'date-fns'

exports = function(barcode){
    const date = addWeeks(new Date(), -10)
    const week = getWeek(date).toString()
    const year = getYear(date).toString()
    const recallTarget = Number(year + week)
    const collection ="mongodb-atlas").db("xNews").collection("products");
    const data = collection.find({ barcode: barcode, recallWeek: { $gte:recallTarget }})
  return data


1 Like

Check this link. It might helps to resolve the issue.