使用议程时,Mongodb Atlas的连接字符串未通过

时间:2019-04-20 22:38:53

标签: javascript node.js mongodb agenda

我是Agenda的新手,我正在尝试将其用于我正在进行的副项目中。我试图了解使用该程序包及其不同功能的工作计划如何工作。我正在连接到我的Mongo数据库,并发布了一个名为job的新hello。当我使用node agenda_dummy.js运行文件时,出现错误TypeError: url.match is not a function。我已经搜索了错误,但是没有任何运气。有关如何解决此问题的任何想法?将发布代码和我的OUTBOX模式。

link to tutorial I am following  https://thecodebarbarian.com/node.js-task-scheduling-with-agenda-and-mongodb

ERROR THAT I AM GETTING

   return url.match(/mongodb(?:\+srv)?:\/\/.*/) !== null;
    TypeError: url.match is not a function`

agenda_dummy.js

var Agenda = require('agenda');
var OUTBOX = require('../helpers/outbox_Schema')
var mongoose = require('mongoose')


var connection = mongoose.connect("mongodb+srv://moe:" + process.env.MONGO_ATLAS_PW + "@sera-outlook-edxbb.mongodb.net/test?retryWrites=true", {
    useNewUrlParser: true
});
  let agenda = new Agenda({
        db: {
            address: connection,
            collection: OUTBOX
        }
    });

async function run() {
      await agenda.start();

    // Define a "job", an arbitrary function that agenda can execute
    agenda.define('hello', () => {
        console.log('Hello, World!');
        process.exit(0);
    });

    // Wait for agenda to connect. Should never fail since connection failures
    // should happen in the `await MongoClient.connect()` call.
    await new Promise(resolve => agenda.once('ready', resolve));

    // Schedule a job for 1 second from now and persist it to mongodb.
    // Jobs are uniquely defined by their name, in this case "hello"
    agenda.schedule(new Date(Date.now() + 1000), 'hello');
    agenda.start();
}

run().catch(error => {
    console.error("The error is ", error);
    // process.exit(-1);
});

outbox_schema.js

var mongoose = require('mongoose')

var my_outbox = mongoose.Schema({
    isRead: Boolean,
    subject: String,
    from: String,
    name: String,
    receivedDateTime: Date,
    sentDateTime: Date,
    type: String,
    conversationId: String
});




module.exports = mongoose.model("OUTBOX", my_outbox);

0 个答案:

没有答案
相关问题