0

I am building an app using Nodejs where I need to perform some functions on a collection on the server side. I have been told to use mongoose to get access to the collection. Here is my code so far:

        var mongoose = require('mongoose');
        var Schema = mongoose.Schema;
        mongoose.connect('mongodb://localhost/test', function(err){
            if(!err){
                console.log("no error!")
            }
        });
        var doc = mongoose.model('foo', 
                       new Schema({name : String}), 
                       'answers'); 
        doc.find({}, function(err,collection){ 
          console.log(collection)
        });

The collection that I want access to is called 'answers'. I want to access the data and make some changes and post those to a another collection. The code above printed an empty array. I would greatly appreciate some help.

anon_945500
  • 269
  • 3
  • 12

1 Answers1

2

Try this:

    var mongoose = require('mongoose');
    var Schema = mongoose.Schema;
    mongoose.connect('mongodb://localhost/test', function(err){
        if(!err){
            console.log("no error!")
        }
    });
    var doc = mongoose.model('answer', new Schema(
        {name : String})
    ); 
    doc.find({}, function(err,collection){ 
      console.log(collection)
    });
zamarrowski
  • 483
  • 2
  • 7