【问题标题】:STRING_URL not defined connecting to mongooseSTRING_URL 未定义连接到猫鼬
【发布时间】:2021-05-01 10:35:27
【问题描述】:
  mongoose.connect(
  STRING_URL(
    'mongodb+srv://Edu:' +
      process.env.MONGO_ATLAS_PW +
      '@node-rest-shop.nzkxl.mongodb.net/myFirstDatabase?retryWrites=true&w=majority'
  ),

  {
    useNewUrlParser: true,
    useUnifiedTopology: true,
  }
);

控制台错误: ReferenceError: STRING_URL 未定义

【问题讨论】:

    标签: node.js mongodb mongoose


    【解决方案1】:

    删除 STRING_URL 部分如下:

    mongoose.connect(
      'mongodb+srv://Edu:' +
      process.env.MONGO_ATLAS_PW +
      '@node-rest-shop.nzkxl.mongodb.net/myFirstDatabase?retryWrites=true&w=majority',
      {
        useNewUrlParser: true,
        useUnifiedTopology: true,
      }
    );
    

    【讨论】:

      【解决方案2】:

      作为一个建议,我推荐使用模板文字

      mongoose.connect(
        `mongodb+srv://Edu:${process.env.MONGO_ATLAS_PW}
         @node-rest-shop.nzkxl.mongodb.net/myFirstDatabase?retryWrites=true&w=majority`,
        {
         useNewUrlParser: true,
         useUnifiedTopology: true
        }
      );
      

      记住你必须使用``backtips

      【讨论】:

        猜你喜欢
        • 2014-11-18
        • 1970-01-01
        • 1970-01-01
        • 2016-04-13
        • 1970-01-01
        • 1970-01-01
        • 2016-04-29
        • 2022-12-12
        相关资源
        最近更新 更多