inserting json value in mongodb server using express.js framework

i want to insert the number generated in to database (i.e test) when a person log in the following are the code file

File :app.js

var express = require('express');
var routes = require('./routes');
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/test');
var schema = mongoose.Schema;
var app = module.exports = express.createServer();


// Configuration
app.configure(function() {
    app.set('views', __dirname + '/views');
    app.set('view engine', 'jade');
    app.use(express.bodyParser());
    app.use(express.methodOverride());
    app.use(express.cookieParser());
    app.use(express.session({
        secret: 'your secret here'
    }));

    app.use(app.router);
    app.use(express.static(__dirname + '/public'));
});

app.configure('development', function() {,
    app.use(express.errorHandler({
        dumpExceptions: true, 
        showStack: true 
    }));
});

app.configure('production', function() {
    app.use(express.errorHandler());
});

app.post('/authenticate', routes.authenticate);
app.get('/login', routes.login);

// Routes
app.get('/', routes.home);
app.post('/', routes.home_post_handler);
app.post('/putdata', routes.putdata);

app.listen(3001, function() {
    console.log("Express server listening on port %d in %s mode", app.address().port, app.settings.env);
});

File: index.js

exports.home = function(req, res) {
    res.redirect('/login');
};

exports.home_post_handler = function(req, res) {
    // message will be displayed on console
    console.log(req.body.message);

    // send back the json of the message received via the textbox
    res.json(req.body.message);
    // or
    //res.send(200);// send 200 for server processing complete
};

exports.login = function(req, res) {
    res.render('login', {
      title: 'login to your system'
    });
};

exports.authenticate = function(req, res) {
    if (req.body.txtlogin == req.body.txtpassword) {

      var _guid = guidgenerator();

      res.json(_guid);
      db.posts.insert(_guid);// this is the main porblem 

    }
};

function guidgenerator() {
    var s4 = function() {
       return (((1 + math.random()) * 0x1000) | 0).tostring(16).substring(1);
    };

    return (s4() + s4() + s4());
}

You are attempting to insert a primitive type into the database. As MongoDB stores JS objects as documents/records, you need to pass an object as the first parameter of insert(). Try the following:

if (req.body.txtlogin == req.body.txtpassword) {
    var guid = guidgenerator();

    // Insert an object with a key named "guid" that has the value of var guid
    db.posts.insert({ "guid": guid });
    res.json(guid);
}

Also going forward please indent your code as per StackOverflow's code formatting syntax. Without formatting most answerers get turned off after skimming through the question, in turn leaving your question unanswered.