'Cannot PubSub from Mongo Db Atlas function

enter image description hereI am using the following Code to do a simple pubsub from a MongoDB function to Google Pubsub. But when I instantiate PubSub : const pubSubClient = new PubSub(); I get TypeError: Value is not an object: undefined. Any hint on how to solve this issue?

exports = function(changeEvent) {
      
    const topicName = 'topicname';
    const data = JSON.stringify({foo: 'bar'});
    
    const {PubSub} = require('pubsub');
    
    const pubSubClient = new PubSub();
    
   async function publishMessageWithCustomAttributes() {
  // Publishes the message as a string, e.g. "Hello, world!" or JSON.stringify(someObject)
  const dataBuffer = Buffer.from(data);

  // Add two custom attributes, origin and username, to the message
  const customAttributes = {
    origin: 'nodejs-sample',
    username: 'gcp',
  };

  const messageId = await pubSubClient
    .topic(topicName)
    .publish(dataBuffer, customAttributes);
  console.log(`Message ${messageId} published.`);
}

publishMessageWithCustomAttributes().catch(console.error);

};



      


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source