I'm building an application with NodeJS that happens to include NowJS. Recently we've decided开发者_开发知识库 to add a database to the application to store user information. We went with MongoDB.
I recently found Mongoose, which looked like it would make my life easier. After a while, I had this in server.js:
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/nowtable');
var Schema = mongoose.Schema;
var UserInfo = new Schema({
username : String,
password : String //i know this is bad but we'll fix it
});
mongoose.model('UserInfo', UserInfo);
var user = db.model('UserInfo');
var admin = new user();
admin.username = "joe schmo";
admin.password = "password1234";
admin.save();
This correctly adds an entry to my database.
However, when I tried to have entries get added dynamically, I ran into problems.
Within index.ejs, inside the now.ready() function, I included a call to now.registerUser(uname, "default password");
Back on server.js, I have this:
everyone.now.registerUser = function(usrname, pwd) {
console.log("This is the username: " + usrname);
console.log("This is the password: " + pwd);
var admin = new user();
}
I get the error:
{ stack: [Getter/Setter],
arguments: [ 'object' ],
type: 'called_non_callable',
message: [Getter/Setter] }
Any help would be appreciated! Thanks!
If you console.log
the error.stack
, you will get a detailed stack trace where the error occurred.
精彩评论