From 60ea7cc443863e005ac4abd07cb6eaf0f309a40b Mon Sep 17 00:00:00 2001 From: Aaron Date: Mon, 11 May 2009 16:38:15 -0400 Subject: [PATCH] count() in shell takes query --- jstests/count.js | 11 +++++++++++ mongo.xcodeproj/project.pbxproj | 2 ++ shell/collection.js | 4 ++-- 3 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 jstests/count.js diff --git a/jstests/count.js b/jstests/count.js new file mode 100644 index 00000000000..4e00d06f4be --- /dev/null +++ b/jstests/count.js @@ -0,0 +1,11 @@ +t = db.jstests_count; + +t.drop(); +t.save( { i: 1 } ); +t.save( { i: 2 } ); +assert.eq( 1, t.find( { i: 1 } ).count() ); +assert.eq( 1, t.count( { i: 1 } ) ); +assert.eq( 2, t.find().count() ); +assert.eq( 2, t.find( undefined ).count() ); +assert.eq( 2, t.find( null ).count() ); +assert.eq( 2, t.count() ); diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj index 37b8a447d07..67a7e389db4 100644 --- a/mongo.xcodeproj/project.pbxproj +++ b/mongo.xcodeproj/project.pbxproj @@ -25,6 +25,7 @@ 931184DC0F83C95800A6DC44 /* message_server_port.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = message_server_port.cpp; sourceTree = ""; }; 931186FB0F8535FF00A6DC44 /* bridge.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = bridge.cpp; sourceTree = ""; }; 931187AE0F85463700A6DC44 /* pair3.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = pair3.js; sourceTree = ""; }; + 931974610FB8C2BD001FE537 /* count.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = count.js; sourceTree = ""; }; 931A027A0F58AA4400147C0E /* jsobjmanipulator.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = jsobjmanipulator.h; sourceTree = ""; }; 93202DE40F879CB600AF3B71 /* all.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = all.js; sourceTree = ""; }; 93278F570F72D32900844664 /* gridfs.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = gridfs.cpp; sourceTree = ""; }; @@ -571,6 +572,7 @@ 93A8D1D10F37544800C92B85 /* jstests */ = { isa = PBXGroup; children = ( + 931974610FB8C2BD001FE537 /* count.js */, 93BC2ADE0FB87442006BC285 /* disk */, 938DECB70FB5017A00C393D8 /* repair.js */, 93C392D00FAA4162007D6E4A /* minmax.js */, diff --git a/shell/collection.js b/shell/collection.js index 0f30e875dab..71e4ef42980 100644 --- a/shell/collection.js +++ b/shell/collection.js @@ -248,8 +248,8 @@ DBCollection.prototype.getIndexSpecs = function(){ } -DBCollection.prototype.count = function(){ - return this.find().count(); +DBCollection.prototype.count = function( x ){ + return this.find( x ).count(); } /**