Skip to content

Instantly share code, notes, and snippets.

@richzw
Created January 12, 2016 11:50
Show Gist options
  • Save richzw/827054124f8b6b0282a4 to your computer and use it in GitHub Desktop.
Save richzw/827054124f8b6b0282a4 to your computer and use it in GitHub Desktop.
var mongoose = require('mongoose');
var c = mongoose.connect('mongodb://localhost/test');
var db = mongoose.connection;
//console.log(c.connection === mongoose.connection);
//var con = mongoose.createConnection('mongodb://localhost/test');
//console.log(con.connection === mongoose.connection);
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function (callback) {
console.log('Connected to Mongo with Mongoose');
insertDocuments(db);
});
var ackSchema = new mongoose.Schema({
hostgroup : String,
host : String,
service : String,
timePeriod : String,
startTime : Number,
ackTime : Number,
deltaTime : Number,
caseNumb : String,
state : Number,
author : String,
ackId : Number,
});
// Creation of the model document
var ackModel = mongoose.model('test', ackSchema, 'test');
var insertDocuments = function(db) {
var ack = new ackModel (
{
ackId: 1184,
author: 'victor.b',
caseNumb: 'C.10',
deltaTime: -1200,
state: 2,
ackTime: 1452590840,
startTime: 1452592040,
timePeriod: 'RESSOURCES-GPE-N1-8/20',
service: 'Service-Random-5M',
host: 'CRI_HOST3',
hostgroup: 'CRIDF' }
);
console.log(ack);
//console.log(getTimeStamp() + 'SAVE Mongoose : ' + ack.author + ' ' + ack.ackId);
ack.save(function (err1, ack) {
if (err1) {
console.log( 'Mongoose .save error : ' + err1);
}
else {
console.log('SAVE Mongoose : ' + ack.author + ' ' + ack.ackId);
}
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment