Skip to content

Instantly share code, notes, and snippets.

@neekey
Created April 29, 2012 11:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neekey/2549663 to your computer and use it in GitHub Desktop.
Save neekey/2549663 to your computer and use it in GitHub Desktop.
mongoose常用的集中find方式
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