Thursday 15 September 2011

javascript - Display the data onto webpage retrieved from mongodb using node.js -


Here my problem is a bit trivial. I'm using a node to write a form. There are buttons, there are drop down boxes. I am able to save data and recover it successfully, but I am not able to write it on the web page. What is the correct way to write data on a page

You can do this easily with Express Mongoose First of all, you will be connected to Mongodi using Mongoze, and then set some variables used to negotiate with Mongosibi from Mongoose (Mongoos.Chem and Mongoos.model), and in the end you will directly set up your Mongodebi You can send the data to the web page through exposures. Res.render function:

  mongoose.connect ('mongodb: // localhost / test', function (mistake) {if (! Err) {console.log ('connect to mongoDB') ;} And {throw it;}}); Var Schema = Mongoose Cm, objectID = schema. Object ID; Var person = new schema ({name: String}); Var person = mongos Model ('person', person); App.get ('/', function (req, res) {person.find ({}, function (mistake, docs) {res.render ('index', {docs: docs}};});});   

After sending data, you can easily reference the 'docs' variable in your web page. Express uses the Z Framework automatically: In Z you can create a list of names of all the people in your database:

  - if (Docs.log) docs p # {person.name } Every person in - else p is not in your database!    

No comments:

Post a Comment