因为我在es6风格中使用过第一次node.js。我无法获取数据。
import mongoose from 'mongoose';
var userSchema = new mongoose.Schema({
username: { type: String, unique: true },
password: String
});
var User = mongoose.model('Users', userSchema);
export default User;
import User from '../schema/UserModel';
const UserCtrl = {};
UserCtrl.getUser = (req, res) => {
log(' In User Controller=========='); // ok
try {
const user = User.find({username: 'me'},(err, userDoc)=>{
res.send(userDoc);
});
}
catch(err) {
error('Error in getting user- ' + err);
// Error in getting user- TypeError: User.find is not a function
res.status(400).send('not ok');
}
}
export default UserCtrl;
routes : app.get('/getUser', UserCtrl.getUser); // ok
猫鼬:v5 表达:v4
请帮帮我。