-
-
Save wookiecooking/6248564 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var mongoose = require('mongoose'); | |
var http = require('http'); | |
var JSONStream = require('JSONStream'); | |
var PersonSchema = new mongoose.Schema({ | |
name: String, | |
num: Number | |
}); | |
mongoose.connect("mongodb://localhost:27017"); | |
var Person = mongoose.model('Person', PersonSchema); | |
var startServer = function(){ | |
var handler = function (req, res) { | |
var query = Person.find({name:'Eric'}); | |
var stream = query.stream(); | |
res.statusCode = 200; | |
stream.pipe(JSONStream.stringify()) | |
.pipe(res); | |
}; | |
http.createServer(handler).listen(8080); | |
console.log("Listening"); | |
}; | |
startServer(); | |
/* | |
var docs = []; | |
for (var i = 0; i <= 50000; i++) { | |
console.log(i); | |
docs.push({name:'Eric', num: i}); | |
} | |
Person.create(docs, function (err, me){ | |
if (err) console.log(err); | |
startServer(); | |
}); | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment