Skip to content

Instantly share code, notes, and snippets.

@wesmaldonado
Created November 17, 2016 20:30
Show Gist options
  • Save wesmaldonado/ba7dc9c79e4017244f52ffbc124789d8 to your computer and use it in GitHub Desktop.
Save wesmaldonado/ba7dc9c79e4017244f52ffbc124789d8 to your computer and use it in GitHub Desktop.
const Rx = require('rxjs/Rx');
const mongoose = require('mongoose');
mongoose.connect('localhost:27017/spot-2016-11-15');
var SpotInstanceSchema = mongoose.Schema({ ami_id: 'string', name: 'string', zone: 'string' });
var SpotInstance = mongoose.model('spot_instance', SpotInstanceSchema);
var cursor = SpotInstance.find({}).cursor();
cursor.on('data', function(doc) {
console.log('data', doc);
});
cursor.on('close', function() {
console.log('close',"DONE!");
});
var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function() {
console.log("connected");
});
//
// rxjx junk
//
//
const myInterval = Rx.Observable.interval(250)
.do(x => console.log("BEFORE", x))
.map(x => x+3)
.do(x => console.log("AFTER", x));
myInterval.subscribe(x => console.log("SUB 1", x));
myInterval.subscribe(x => console.log("SUB 2", x));
{
"name": "mongoose-playground",
"version": "1.0.0",
"description": "Playing with mongoose and rxjs",
"main": "app.js",
"scripts": {
"test": "npm test",
"start": "node app.js"
},
"author": "wfm",
"license": "BSD-2-Clause",
"dependencies": {
"mongoose": "^4.6.8",
"rxjs": "^5.0.0-rc.3"
},
"devDependencies": {
"babel-cli": "^6.18.0",
"babel-preset-es2015": "^6.18.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment