I was trying out mongodb and nodejs on openshift, using mongojs to interface between nodejs and mongodb.
In mongoshell, I executed "use nodejs" and assigned a "scores" collection. I have inserted the data in it and its correctly displaying.
In the app.js file of nodeserver, I have the following code:
self.routes['/db'] = function(req, res) {
var db = require("./db");
db.scores.find(function(err,docs){res.send(docs);});
};
and in my javascript db.js file I have the following code:
var dbName = "/nodejs";
var databaseUrl = process.env.OPENSHIFT_MONGODB_DB_USERNAME + ":" + process.env.OPENSHIFT_MONGODB_DB_PASSWORD + "@" + process.env.OPENSHIFT_MONGODB_DB_HOST + ":" + process.env.OPENSHIFT_MONGODB_DB_PORT+ dbName;
// "username:[email protected]/mydb"
var collections = ["scores"]
var db = require("mongojs").connect(databaseUrl, collections);
module.exports = db;
I am unable to get any data when I go to url: mydomain.com/db
Can you please guide me on where I am doing wrong. The database is connecting. I am not able to find all the data from the scores collection.
self.routes['/db'] = function(req, res) {
var db = require("./db");
db.scores.find(function(err,docs){res.send(docs);});
};