0

im attempting a "simple" connection to mongodb via an express app, the code follows:

var express = require("express");
var http = require("http");
var mongoose = require("mongoose");

//database connections
var mongoose = require("mongoose"); 
mongoose.connect('mongodb://localhost:27017/contactlist');

var contactSchema = new mongoose.Schema({
    name: String,
    email: String,
    number: String
});

var Contact = mongoose.model("Contact", contactSchema);

exports.getcontactlist = function (request, response) {

    console.log("connecting to mongo again...");

    Contact.find({ }, function (err, docs) {

        console.log(docs);
        response.send(docs);
    });

};

The result that is returned is always "[ ]".

Please can someone point me in the right direction?

EDIT::

Yes the database is populated

enter image description here

vicgoyso
  • 636
  • 1
  • 14
  • 35
  • What's the name of the collection in the `contactlist` database that contains the docs you're expecting to see? – JohnnyHK Oct 05 '15 at 20:52
  • Hi JohnnyHK Im not 100% sure what youmean... the db im attempting to connect to is called "contactlist", using mongo in the console i can retrieve the records by using db.contactlist.find(); – vicgoyso Oct 05 '15 at 20:59
  • Your `mongoose.connect` call is connecting to the `contactlist` database on the local server. That database can contain a number of collections. If you enter `db` at the mongo console prompt, what does it return? That tells you the current database you're working with in the console. – JohnnyHK Oct 05 '15 at 21:06
  • Have you tried installing [Robomongo](http://robomongo.org/) to check if your database is filled at all? – CherryNerd Oct 05 '15 at 21:06
  • Typing "db" returns "contactlist"... plus the database is populated, i have updated the original post with a screenshot that displays the results within the console. – vicgoyso Oct 05 '15 at 21:19
  • YES that solved it, thanks a bunch!!! (tried voting up but i don't have privileges yet). – vicgoyso Oct 05 '15 at 21:30

0 Answers0