My goal is to update values that stored in MongoDB, therefore I have decided to use mongoose to see data and edit them, However; it gives me an error. Maybe I am in the wrong way, does anybody has already implemented this kind work.
import * as React from "react";
import * as mongoose from 'mongoose'
export interface State {
}
export default class mongodb extends React.Component<State> {
constructor(props: {}) {
super(props);
}
private setupDb() : void {
var mongoDb = 'mongodb://localhost/My_db';
mongoose.connect(mongoDb);
console.info("Connected to Mongo.")
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'MongoDB Connection error'));
}
componentDidMount(){
this.setupDb()
}
render() {
return (<div></div> );
}
}
The error:
TypeError: mongoose__WEBPACK_IMPORTED_MODULE_1__.connect is not a function