node.js - Mongoose MongoDb not showing schemas or models in Node Shell -


i'm new mongoose , mongodb. after creating schemas , models:

one@demo ~/cloudimageshare-monitoring/project/app/data $ tree  . |-- models |   |-- cpu.js |   |-- httpport.js |   |-- memory.js |   `-- network.js `-- schemas     |-- cpu.js     |-- http_port.js     |-- memory.js     `-- network.js  2 directories, 8 files 

one@demo ~/cloudimageshare-monitoring/project/app/data $ cat models/cpu.js:

var mongoose = require('mongoose'); var cpuschema = require(../schemas/cpu);  var cpu = mongoose.model('cpu', cpuschema);  module.exports = cpu; 

one@demo ~/cloudimageshare-monitoring/project/app/data $ cat schemas/cpu.js:

var mongoose = require('mongoose'); var schema = mongoose.schema,  var cpuschema = new schema({     'timestamp' : { type : date, index: true },     "avaiable" : boolean,     "status" : string,     "metrics" : [ "15m": [ "data" : number,                            "type" : string,                            "unit" : string                           ],                    "5m": [ "data" : number,                            "type" : string,                            "unit" : string                           ],                    "1m": [ "data" : number,                            "type" : string,                            "unit" : string                          ]                 ] })  module.exports = cpuschema;  one@demo ~/cloudimageshare-monitoring/project/app/data $  

when connecting database in node shell, not showing schemas or models. why this?

> var dburl = 'mongodb://localhost/database'; undefined > var db = require('mongoose').connect(dburl); undefined > db   > db { connections:     [ { base: [circular],        collections: {},        models: {},        replica: false,        hosts: null,        host: 'localhost',        port: 27017,        user: undefined,        pass: undefined,        name: 'database',        options: [object],        otherdbs: [],        _readystate: 1,        _closecalled: false,        _hasopened: true,        _listening: true,        _events: {},        db: [object] } ],   plugins: [],   models: {},   modelschemas: {},   options: { pluralization: true } } 

you'll need require model in shell. mongoose won't recognize you've defined model until you've called mongoose.model, , that's called when require models/cpu.js.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -