11// Mongo
22import mongodb = require( 'mongodb' ) ;
33
4- var server = new mongodb . Server ( 'localhost' , 27017 , { auto_reconnect : true } )
4+ var server = new mongodb . Server ( 'localhost' , 27017 , { auto_reconnect : true } ) ;
55var db = new mongodb . Db ( 'mydb' , server , { w : 1 } ) ;
66db . open ( function ( ) { } ) ;
77
@@ -33,9 +33,9 @@ export interface Image {
3333export function getUser ( id : string , callback : ( user : User ) => void ) {
3434 db . collection ( 'users' , function ( error , users ) {
3535 if ( error ) { console . error ( error ) ; return ; }
36- users . findOne ( { _id : id } , function ( error , user ) {
37- if ( error ) { console . error ( error ) ; return ; }
38- callback ( user ) ;
36+ users . find ( { _id : id } ) . batchSize ( 10 ) . nextObject ( function ( error , user ) {
37+ if ( error ) { console . error ( error ) ; return ; }
38+ callback ( user ) ;
3939 } ) ;
4040 } ) ;
4141}
@@ -53,7 +53,7 @@ export function getUsers(callback: (users: User[]) => void) {
5353export function getImage ( imageId : string , callback : ( image : Image ) => void ) {
5454 db . collection ( 'images' , function ( error , images_collection ) {
5555 if ( error ) { console . error ( error ) ; return ; }
56- images_collection . findOne ( { _id : new mongodb . ObjectID ( imageId ) } , function ( error , image ) {
56+ images_collection . find ( { _id : new mongodb . ObjectID ( imageId ) } ) . batchSize ( 10 ) . nextObject ( function ( error , image ) {
5757 if ( error ) { console . error ( error ) ; return ; }
5858 callback ( image ) ;
5959 } ) ;
0 commit comments