javascript - how to get inserted value from data base? -
i using mongo db using express + node js .i inserted 1 value in data base .
mongodb shell version: 3.0.4 connecting to: localhost:27017/local > use hockey switched db hockey > db.playes.insert({ name:"naveen" }) writeresult({ "ninserted" : 1 })
i make hocket scehma name , players table name , add 1 entry name:"naveen"..which inserted .
now want retrieve value using connecting mongo db.
var express=require('express'); var app =express(); var mongoclient = require('mongodb').mongoclient; var assert = require('assert'); app.get('/app',function(req,res){ mongoclient.connect(url, function(err, db) { assert.equal(null, err); console.log("connected correctly server."); db.close(); }); }) var url = 'mongodb://localhost:27017/test'; app.listen(3000,function(){ console.log('server runninngn') })
when user type http://localhost:3000/app gives {"name" :"naveen"}
expected value
{"name" :"naveen"}
Comments
Post a Comment