0

I have looked this up for a while now and I am stuck . I also referred this question and this question and tried it out but I havent been able to get it running.

This is a brief overview of my project: I have a python script that parses data from some logs on a server everyday. each log is a python object which is stored in a collection with the corresponding date in db 'stabilitylogs' in mongoDB.

I have now installed node and mongoose and I am trying to pull out this data from a particular collection named - 130702. I am getting the following error:

C:\node_app\node_modules\mongodb\lib\mongodb\connection\server.js:570

throw err; ^ ReferenceError: Schema is not defined

My stabilitylog.js looks like this:

            var mongoose = require('mongoose');
            mongoose.connect('mongodb://localhost/stabilitylogs');

            var db = mongoose.connection;
            db.on('error', console.error.bind(console, 'connection error:'));
            db.once('open', function callback () {
                var rackSchema=new Schema({
                    _id: {type: String },
                    Headend:{
                        Name: String,
                        Rack: {
                            TestInfo:{
                                ScriptStart: String,
                                TotalReboots: String,
                                ScriptLoopCount: String,
                                ScriptName: String,
                                ScriptStop: String,
                                SystemName: String,
                                TotalSTBs: String,
                                PerReboots: String,
                                RunTime: String,
                                BuildVer: String
                                },
                            StbData: [{
                                Status: String,
                                UpTime: String,
                                DBType: String,
                                IP: String,
                                DBVersion: String,
                                RebootData: String,
                                MAC: String,
                                MWApp: String,
                                OS: String
                                },],
                            Number: String
                            }
                        }
                    },
                {collection: '130702'});

                var doc = mongoose.model(rackschema, '130702');
                doc.find();
                });

I am really new to this and sure that I have many errors in my code but I really need some help here. I am running my entire app on windows 7- installed mongodb ver2.2.4 with the MSI installer and nodeJS - v0.10.12. I installed mongodb and mongoose modules with npm install by writing a package.json file.

Any help is highly appreciated. Also, please let me know if more information is required.

Community
  • 1
  • 1
Isis285
  • 11
  • 2

1 Answers1

1

Unless you already have var Schema = mongoose.Schema; in your file, you need to use new mongoose.Schema like JohnnyHK said. In addition the find method on a mongoose model should looks something like this if you want the query to execute immediately.

doc.find({}, function(err,collection){ 
//do something with the collection
});
  • This doesnt seem to work. :( I tried checking if it is able to pull out data from the db. I get a '0' as the length of collection even though it is not empty. Where am I going wrong? `var MongoClient = require('mongodb').MongoClient; //connect to db MongoClient.connect("mongodb://localhost:27017//test", function(err, db) { if(!err) { console.log("we are connected"); var collection = db.collection('movies'); collection.find().toArray(function(err, items) { console.log(items.length);}); } });` – Isis285 Jul 09 '13 at 05:47
  • sorry for the formatting! I dont know how to edit it properly. – Isis285 Jul 09 '13 at 05:48