简体   繁体   中英

Node.js mongoose connect error

I have node.js project which contain mongo database. I use mongoose schema. 3 file in project are: index.js, users.js and db.js. when I want to connect mongodb via mongoose, I can't. Here is my code. when it runs it says

"error is: TypeError: parseFn is not a function."

pls help!!

db.js

const mongoose=require('mongoose');

mongoose.Promise = require('bluebird');
mongoose.connect('mongodb://localhost:27017/myDB', { useNewUrlParser:true}).then(
(res) => {
console.log("Success!!.")
}).catch((e) => {console.log("error is: " + e);});

users.js

var mongoose = require('mongoose');

var Schema = mongoose.Schema;

var userSchema= new Schema({
id:{type : Number, required: true, unique:true},
username : String,
password : String }, {collection: 'userTB'});

var userS= mongoose.model('userTBL', userSchema);

module.exports=userS;

index.js

...
var db=require('./app_server/models/db');
...

I'm not sure but I guess I faced the same kinda error when I was a newbie in MongoDB. If I'm not wrong this error is because you haven't actually started your local MongoDB server yet. You actually have to start the MongoDB server manually to connect to it. The command to start mongo server from the terminal is something like:

mongod --dbpath /data/db

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM