1
1
// Mongo
2
2
import mongodb = require( 'mongodb' ) ;
3
3
4
- var server = new mongodb . Server ( 'localhost' , 27017 , { auto_reconnect : true } )
4
+ var server = new mongodb . Server ( 'localhost' , 27017 , { auto_reconnect : true } ) ;
5
5
var db = new mongodb . Db ( 'mydb' , server , { w : 1 } ) ;
6
6
db . open ( function ( ) { } ) ;
7
7
@@ -33,9 +33,9 @@ export interface Image {
33
33
export function getUser ( id : string , callback : ( user : User ) => void ) {
34
34
db . collection ( 'users' , function ( error , users ) {
35
35
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 ) ;
39
39
} ) ;
40
40
} ) ;
41
41
}
@@ -53,7 +53,7 @@ export function getUsers(callback: (users: User[]) => void) {
53
53
export function getImage ( imageId : string , callback : ( image : Image ) => void ) {
54
54
db . collection ( 'images' , function ( error , images_collection ) {
55
55
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 ) {
57
57
if ( error ) { console . error ( error ) ; return ; }
58
58
callback ( image ) ;
59
59
} ) ;
0 commit comments