Created
April 29, 2012 11:40
-
-
Save neekey/2549663 to your computer and use it in GitHub Desktop.
mongoose常用的集中find方式
This file contains 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 DB = require( '../../database/' ); | |
var mongoose = require( 'mongoose' ); | |
var Item = mongoose.model( 'item' ); | |
describe( 'mongooseTest', function(){ | |
it( 'localtion test', function(){ | |
var itemsLen = 0; | |
runs(function (){ | |
Item.find({ location: { $near: [1328067661923, 1328067913590], $maxDistance: 10791000000 } }, function ( err, items ){ | |
itemsLen = items.length; | |
}); | |
}); | |
waitsFor( function (){ | |
return itemsLen; | |
}, 5000 ); | |
runs(function(){ | |
expect( itemsLen ).toBe( 3 ); | |
}); | |
}); | |
it( 'in', function(){ | |
var itemsLen = 0; | |
var itemIds = [ '4f9d22eabb1c3cf31e000009', '4f9d23040436e1051f000009', '4f9d22eabb1c3cf31e000007' ]; | |
runs(function (){ | |
Item.find({ _id: { $in: itemIds }}, function ( err, items ){ | |
itemsLen = items.length; | |
}); | |
}); | |
waitsFor( function (){ | |
return itemsLen; | |
}, 5000 ); | |
runs(function(){ | |
expect( itemsLen ).toBe( 3 ); | |
}); | |
}); | |
it( 'regex', function(){ | |
var itemsLen = 0; | |
runs(function (){ | |
Item.find({ title: { $regex: /ell/i }}, function ( err, items ){ | |
itemsLen = items.length; | |
}); | |
}); | |
waitsFor( function (){ | |
return itemsLen; | |
}, 5000 ); | |
runs(function(){ | |
expect( itemsLen ).toBe( 1 ); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment