//dbconf
var mongo = require('mongo'); //引入mysql模块
var mongoose = require('mongoose'); //引入mongoose模块
var shortid = require('shortid');
var db = mongoose.connect('mongodb://127.0.0.1/FBMS')
var Schema = mongoose.Schema;
db.connection.on('error',function(error){
console.log(error);
})
db.connection.on('open',function(){
console.log('open mongoDB');
})
var accountSchema= new Schema({
_id: {
type: String,
unique: true,
'default': shortid.generate
},
username:{type:String ,index:{unique:true}},
password:String,
avataimgurl:{type:String,default:''},
cellphone:Number,
address:String,
device:{stuff:String},
remarks:String
})
module.exports= mongoose.model('account',accountSchema); //连接对象导出
//account
var dbconf = require('./dbconf'); //导入dbconf模块
var data={code:'200',msg:'',username:''};
var checkAccount={
check:function(_req,_res){
dbconf.find({'username':'wangpeng'},function(err,results,fields){
if(err){
console.log("数据库报错:"+err);
console.log(":"+results);
console.log(":"+fields);
}
});
}
}
module.exports = checkAccount;
迷茫2017-04-17 16:28:04
The problem is vague, the code is messy, and the error message is not uploaded. Don't know what you want to ask. The callback error is null, is it err? Or results?
巴扎黑2017-04-17 16:28:04
This question was a bit urgent when I asked it. Sorry, the question is like this now. If I connect to the database but no collection or document is found, will the callback err display null? My model is exported as module.exports= mongoose.model('account',accountSchema); But the name of the collection built in mongodb is accounts. Is this added by mongose itself?