How to pass data to Mongodb using Node.js, websocket and total.js

I am trying to pass data to Mongodb using Websocket and total.js. In my homepage.html I can get the user input and connect to the server via websocket after clicking the save button.

In default.js is my server side code. At this point the app hat got the user input and connected to the server correctly, but how can I save data to mongodb now?

This is my homepage.html

<br />
<div>
<input type="text" name="message" placeholder="Service" maxlength="200" style="width:500px" />
<button name="send" >Save</div>
</div>
<br />

<script type="text/javascript">
  var socket = null;
  $(document).ready(function() {
    connect();
    $('button').bind('click', function() {

        if (this.name === 'send') {                     
            console.log(send());
            return;
        }           

    });
});
function connect() {
    if (socket !== null)
        return;
    socket = new WebSocket('ws://127.0.0.1:8000/');

    socket.onopen = function() {
        console.log('open');
    };

    socket.onmessage = function(e) {
        var el = $('#output');
        var m = JSON.parse(decodeURIComponent(e.data)).message;
        el.val(m + '\n' + el.val());
    };

    socket.onclose = function(e) {
        // e.reason ==> total.js client.close('reason message');
        console.log('close');
    };
}

function send() {
    var el = $('input[name="message"]');
    var msg = el.val();

    if (socket !== null && msg.length > 0)
        socket.send(encodeURIComponent(JSON.stringify({ message: msg })));

    el.val('');
    return msg;
}

This is my default.js

 exports.install = function(framework) {
 framework.route('/', view_homepage);
 framework.route('/usage/', view_usage);
 framework.websocket('/', socket_homepage, ['json']);

 };

 function view_usage() {
 var self = this;
 self.plain(self.framework.usage(true));
 }

function view_homepage() {
var self = this;
self.view('homepage');
}
function socket_homepage() {
    var controller = this;
    controller.on('open', function(client) {
    console.log('Connect');    
});

controller.on('message', function(client, message) {
    console.log(message);
 /*
 var self = this;
 var message = MODEL('message').schema;
 var model = self.body;
 var message = new message({ message: model.message }).save(function(err) {
    if (err)
        self.throw500(err);

    // Read all messages
    message.find(self.callback());
});   
*/      
});
controller.on('error', function(error, client) {
    framework.error(error, 'websocket', controller.uri);
});
}

Any help Please!!!

This is complete project

---Update---

In this function i use to save data to MongoDB but it didn't give any error.also Didnt save the data to database.i not sure my code is write or wrong

  controller.on('message', function(client, message) {
    console.log(message);
 /*
 var self = this;
 var message = MODEL('message').schema;
 var model = self.body;
 var message = new message({ message: model.message }).save(function(err) {
    if (err)
        self.throw500(err);

    // Read all messages
    message.find(self.callback());
});   
*/      
});

This my mongoose.js

var mongoose = require('mongoose');
mongoose.connect('mongodb://totaldemo:123456@ds029979.mongolab.com:29979/totaldemo');
global.mongoose = mongoose;

This is my user.js

 var userSchema = mongoose.Schema({ user: String})
 exports.schema = mongoose.model('user', userSchema,'user');
 exports.name = 'user';

I don't know totaljs framework at all, but i see some issues already with plain javascript.

First of all, i suggest You set up Your model like this:

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var userSchema = new Schema({
  user: String
});

module.exports = mongoose.model('User', userSchema);

and then in controller, when You import:

var User = require('path/to/user/file')

You can use it like this straight away:

User.find()

Also - i totally dont get what are You doing later. You defined user model and exported NOTHING MORE than a STRING. Only tthing it will do is, that when You import that user to variable User, the User.name will === to 'user' string. so in Your example it would be:

var User = require('path/to/user/model/file')
console.log(User.name) // prints 'user'

and nothing more! There are no models attached to that export. Maybe its how totaljs works, but i VERY doubt it.

Later on - You try to ... use message model. Where it comes from? You defined user model, not message model.

Another thing - as i stated - i dont know totaljs, but I doubt it ask YOu to define var model, and then never use variable model.

I strongly suggest using plain node with mongoose first, then try to integrate it with any fullstack.

For sure its not a solution, but maybe it points out some problems in Your code and will help.

EDIT:

I looked quickly in totaljs, and it looks that You really should export string (which is little weird and doing magic stuff:) ), but its NOT mongoose, and i guess will ONLY work with native totaljs model solution. You cant use mongoose and totaljs like that. I dont know how much not using native totaljs models system ruins framework other options, but its probably safer to use native one.

Honestly, i dont have time to look deeper into docs, but google says nothing about sql or even mongo inside of totaljs docs... so, You have to figure it out :)

EDIT2 i found https://github.com/totaljs/examples/tree/master/mongoose and it looks weird... check if that example works (looks like You seen it, Your code is similar :)). check if You're mongod is working, check if You can conenct from plain node...

Honestly sorry, i surrender. Totaljs has to much magic and abstraction for me to help You out with this :(. Hope You will find Your answer.