【问题标题】:Problem connecting with Mongoose - TypeError: mongoose.connect is not a function与 Mongoose 连接时出现问题 - TypeError: mongoose.connect is not a function
【发布时间】:2020-11-05 05:49:22
【问题描述】:

我在我的 React 应用程序中连接到 Mongoose 时遇到了一些问题。我正在尝试将 Azure Cosmos DB 实例与 Mongo API 连接。

这是我的 app.js:

import React from 'react';


const mongoose = require('mongoose');
const dbUri = `SecretDBConnectionString`
mongoose.createConnection(dbUri, { useNewUrlParser: true })
    .then(console.log('MongoDB Connected..'))
    .catch(err => console.log(err));


class App extends React.Component {
  render(){
    return(
      <div></div>
    )
  }
}

export default App;

我收到此错误:

TypeError: mongoose.createConnection 不是函数

我已经用谷歌搜索了错误,但没有找到与我的情况有关的内容。我觉得我错过了一些非常基本的东西。

【问题讨论】:

    标签: node.js reactjs mongodb mongoose


    【解决方案1】:

    经过进一步研究,我了解到您无法从客户端初始化 MongoDB。

    【讨论】:

      猜你喜欢
      • 2020-11-17
      • 1970-01-01
      • 2022-10-22
      • 2015-11-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多