在我的UserSchema (我的InfoUser.js中)中,这是我如何构造代码的方法
InfoUser.js
var mongoose = require('mongoose');
//User Schema
//authToken and isAuthenticated is for UserSchema of email-verification
var UserSchema = mongoose.Schema({
username:{
type: String,
index:true,
unique:true
},
influenceid:{
type:String
},
question:{
type:String
},
amount:{
type:Number
},
ifAnswer:{
type:String
},
TimeAnswer:{
type:Date
// default:Date.now
},
Done:{
type:Boolean
}
},{timestamps:{createdAt:'created_at'}});
//accesible variable from the outside
var InfoUser = module.exports = mongoose.model('infousers', UserSchema);
//create the user
module.exports.createUser= function(newUser, callback){
newUser.save(callback);
}在我的server.js上,我插入了这样的数据
server.js
socket.on('dollar quest', function(dolquest,dolamnt,uid,stud,stat){
var info = new InfoUser({
username: stud,
amount:parseInt(dolamnt),
question: dolquest,
influenceid:uid
});
InfoUser.createUser(info,function(err,user){
if(err)throw err;
console.log(user);
});
io.emit('tech notif',uid,stud,stat);
});
});现在,我插入数据的代码很好,但问题是,每当我尝试执行另一个事务时,它就不再插入。谁来帮帮我拜托。为什么不在mlab上插入更多的数据。
发布于 2017-08-02 14:13:15
使用
info.save(function(err, result)
{
response.json({code :0 , result});
});https://stackoverflow.com/questions/45461098
复制相似问题