node.js - NodeJS Mongoose Not Save Data -


my system create around 30 collection every hour. server thousands request 1 hour. have big data , multiple collections. , use mongodb-nodejs saving data.

the modelcontrol function of paritemodel class @ paritemodel.js -as below codes- check if schema created before. , create schema or use created schema.

first collections creating , saving data mongodb. when create collections it's not doing. example:

eurjpy_20160107_16 collection created eurjpy_20160107_17 collection not create. have check mongoose.models @ modelparite.js eurjpy_20160107_17 created instance created eurjpy_20160107_17 schema not saved database.

my server files this:

app.js file bootstrap file:

var http = require('http'),  dispatcher = require('httpdispatcher');    require('./mongo.js');    function handlerequest(request, response){      try {          dispatcher.dispatch(request, response);      } catch(err) {          console.log(err);      }  }    var server = http.createserver(handlerequest);    server.listen(3663, function(){          console.log('listening port: ' + 3663);  });

this mongo.js call in app.js. file uses save data mongodb:

var dispatcher = require('httpdispatcher'),  url = require('url'),  moment = require('moment'),  md = moment().format("yyyymmdd_hh"),  mymodel = require('./modelparite.js');    dispatcher.onget('/mongo', function(req, res){            var url_parts = url.parse(req.url, true);          // collection name. output this: usdtry_20160107_16          var colname = url_parts.query.symbol + '_' + md;            var tarih = new date();            var paritemodel = mymodel.returnmodel(colname);          var yeniparite = new paritemodel({                  symbol: url_parts.query.symbol,                  bid: url_parts.query.bid,                  ask: url_parts.query.ask,                  timeup: moment(tarih).format("yyyy-mm-dd hh:mm:ss")          });            yeniparite.save(function (err, data) {                  if (err) console.log(err);                  console.dir(data,true);          });            res.writehead(200, {'content-type': 'text/html'});          res.end();  });

and model modelparite.js file call in mongo.js. file uses create schema mongoose:

    var mongoose = require('mongoose'),      helper = require('./helper.js');      require('mongoose-double')(mongoose);        mongoose.connect('mongodb://localhost:27017/forex');        var paritemodel = {                pariteschema: "",                initschema: function(){                        var schema = mongoose.schema;                      this.pariteschema = new schema({                              symbol: string,                              bid: mongoose.schema.types.double,                              ask: mongoose.schema.types.double,                              timeup: date                      });              },                modelcontrol: function(modelname){                      if(mongoose.models[modelname]){                              return true;                      }                      return false;              },                returnmodel: function(modelname){                        modelname = helper.whichparity(modelname);                      //console.log(modelname);                        if(this.modelcontrol(modelname)){                              //console.log(mongoose.model(modelname));                              return mongoose.model(modelname);                      }else{                              this.initschema();                              return mongoose.model(modelname, this.pariteschema);                      }              },      }        module.exports = paritemodel;


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -