summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--client/dbclient.cpp11
-rw-r--r--client/dbclient.h5
-rw-r--r--client/examples/clientTest.cpp10
-rw-r--r--client/examples/tutorial.cpp2
-rw-r--r--client/gridfs.cpp9
-rw-r--r--client/gridfs.h2
-rw-r--r--db/db.sln12
-rw-r--r--db/jsobj.cpp14
-rw-r--r--db/jsobj.h29
-rw-r--r--dbtests/jsobjtests.cpp4
-rw-r--r--dbtests/jsontests.cpp2
-rw-r--r--dbtests/matchertests.cpp4
-rw-r--r--dbtests/pairingtests.cpp4
13 files changed, 64 insertions, 44 deletions
diff --git a/client/dbclient.cpp b/client/dbclient.cpp
index 10eba7050b9..c81c1d0dd50 100644
--- a/client/dbclient.cpp
+++ b/client/dbclient.cpp
@@ -91,10 +91,19 @@ namespace mongo {
if ( info == 0 )
info = &o;
BSONObjBuilder b;
- b.appendInt(command, 1);
+ b.append(command, 1);
return runCommand(dbname, b.done(), *info);
}
+ unsigned long long DBClientWithCommands::count(const char *ns, BSONObj query) {
+ BSONObj cmd = BSON( "count" << ns << "query" << query );
+ string db = nsToClient(ns);
+ BSONObj res;
+ if( !runCommand(db.c_str(), cmd, res) )
+ uasserted(string("count fails:") + res.toString());
+ return res.getIntField("n");
+ }
+
BSONObj getlasterrorcmdobj = fromjson("{getlasterror:1}");
string DBClientWithCommands::getLastError() {
diff --git a/client/dbclient.h b/client/dbclient.h
index 33d9e41a469..e2b5e5c790a 100644
--- a/client/dbclient.h
+++ b/client/dbclient.h
@@ -266,6 +266,11 @@ namespace mongo {
*/
virtual bool auth(const char *dbname, const char *username, const char *pwd, string& errmsg, bool digestPassword = true);
+ /** count number of objects in collection ns that match the query criteria specified
+ throws UserAssertion if database returns an error
+ */
+ unsigned long long count(const char *ns, BSONObj query);
+
string createPasswordDigest( const char * username , const char * clearTextPassword );
/** returns true in isMaster parm if this db is the current master
diff --git a/client/examples/clientTest.cpp b/client/examples/clientTest.cpp
index 36288da4d3f..222847468fb 100644
--- a/client/examples/clientTest.cpp
+++ b/client/examples/clientTest.cpp
@@ -29,7 +29,7 @@ int main() {
assert( conn.findOne( ns , BSONObjBuilder().obj() ).isEmpty() );
// test insert
- conn.insert( ns ,BSONObjBuilder().append( "name" , "eliot" ).append( "num" , 1 ).obj() );
+ conn.insert( ns ,BSON( "name" << "eliot" << "num" << 1 ) );
assert( ! conn.findOne( ns , BSONObjBuilder().obj() ).isEmpty() );
// test remove
@@ -38,7 +38,7 @@ int main() {
// insert, findOne testing
- conn.insert( ns , BSONObjBuilder().append( "name" , "eliot" ).append( "num" , 1 ).obj() );
+ conn.insert( ns , BSON( "name" << "eliot" << "num" << 1 ) );
{
BSONObj res = conn.findOne( ns , BSONObjBuilder().obj() );
assert( strstr( res.getStringField( "name" ) , "eliot" ) );
@@ -48,7 +48,7 @@ int main() {
// cursor
- conn.insert( ns ,BSONObjBuilder().append( "name" , "sara" ).append( "num" , 2 ).obj() );
+ conn.insert( ns ,BSON( "name" << "sara" << "num" << 2 ) );
{
auto_ptr<DBClientCursor> cursor = conn.query( ns , BSONObjBuilder().obj() );
int count = 0;
@@ -60,7 +60,7 @@ int main() {
}
{
- auto_ptr<DBClientCursor> cursor = conn.query( ns , BSONObjBuilder().append( "num" , 1 ).obj() );
+ auto_ptr<DBClientCursor> cursor = conn.query( ns , BSON( "num" << 1 ) );
int count = 0;
while ( cursor->more() ) {
count++;
@@ -70,7 +70,7 @@ int main() {
}
{
- auto_ptr<DBClientCursor> cursor = conn.query( ns , BSONObjBuilder().append( "num" , 3 ).obj() );
+ auto_ptr<DBClientCursor> cursor = conn.query( ns , BSON( "num" << 3 ) );
int count = 0;
while ( cursor->more() ) {
count++;
diff --git a/client/examples/tutorial.cpp b/client/examples/tutorial.cpp
index 5f2d3dbeb79..b5f2eb8788e 100644
--- a/client/examples/tutorial.cpp
+++ b/client/examples/tutorial.cpp
@@ -11,6 +11,8 @@ void run() {
cout << "connected ok" << endl;
BSONObj p = BSON( "name" << "Joe" << "age" << 33 );
c.insert("tutorial.persons", p);
+
+ cout << "count:" << c.count(
}
int main() {
diff --git a/client/gridfs.cpp b/client/gridfs.cpp
index 987f6c49b51..bd17894f7b2 100644
--- a/client/gridfs.cpp
+++ b/client/gridfs.cpp
@@ -10,7 +10,7 @@
namespace mongo {
- const gridfs_offset DEFAULT_CHUNK_SIZE = 256 * 1024;
+ const unsigned DEFAULT_CHUNK_SIZE = 256 * 1024;
Chunk::Chunk( BSONObj o ){
_data = o;
@@ -19,7 +19,7 @@ namespace mongo {
Chunk::Chunk( BSONElement fileId , int chunkNumber , const char * data , int len ){
BSONObjBuilder b;
b.appendAs( fileId , "files_id" );
- b.appendInt( "n" , chunkNumber );
+ b.append( "n" , chunkNumber );
b.appendBinDataArray( "data" , data , len );
_data = b.obj();
}
@@ -47,7 +47,8 @@ namespace mongo {
{
BSONObjBuilder b;
b << "filename" << filename ;
- b << "length" << length ;
+ massert("large files not yet implemented", length <= 0xffffffff);
+ b << "length" << (unsigned) length ;
b << "chunkSize" << DEFAULT_CHUNK_SIZE ;
OID id;
@@ -102,7 +103,7 @@ namespace mongo {
_exists();
BSONObjBuilder b;
b.appendAs( _obj["_id"] , "files_id" );
- b.appendInt( "n" , n );
+ b.append( "n" , n );
BSONObj o = _grid->_client.findOne( _grid->_chunksNS.c_str() , b.obj() );
assert( ! o.isEmpty() );
diff --git a/client/gridfs.h b/client/gridfs.h
index 866513757d9..3a8428e2cb0 100644
--- a/client/gridfs.h
+++ b/client/gridfs.h
@@ -6,7 +6,7 @@
namespace mongo {
- typedef unsigned long gridfs_offset;
+ typedef unsigned long long gridfs_offset;
class GridFS;
class GridFile;
diff --git a/db/db.sln b/db/db.sln
index c2e08932b3d..e12ae953199 100644
--- a/db/db.sln
+++ b/db/db.sln
@@ -5,7 +5,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "db", "db.vcproj", "{215B2D6
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mongos", "..\dbgrid\dbgrid.vcproj", "{E03717ED-69B4-4D21-BC55-DF6690B585C6}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "clienttests", "clienttests", "{4082881B-EB00-486F-906C-843B8EC06E18}"
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "examples", "examples", "{4082881B-EB00-486F-906C-843B8EC06E18}"
ProjectSection(SolutionItems) = preProject
..\client\examples\authTest.cpp = ..\client\examples\authTest.cpp
..\client\examples\clientTest.cpp = ..\client\examples\clientTest.cpp
@@ -33,8 +33,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "dbtests", "dbtests", "{C72E
..\dbtests\socktests.cpp = ..\dbtests\socktests.cpp
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "tutorial", "..\client\examples\tutorial\tutorial.vcproj", "{C5EC52B2-1E28-4AF1-A244-CBB514C361C0}"
-EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "shell", "shell", "{2CABB3B8-C9A6-478D-9463-0B37799ED708}"
ProjectSection(SolutionItems) = preProject
..\shell\dbshell.cpp = ..\shell\dbshell.cpp
@@ -75,14 +73,6 @@ Global
{E03717ED-69B4-4D21-BC55-DF6690B585C6}.release_nojni|Win32.Build.0 = Debug|Win32
{E03717ED-69B4-4D21-BC55-DF6690B585C6}.Release|Win32.ActiveCfg = Release|Win32
{E03717ED-69B4-4D21-BC55-DF6690B585C6}.Release|Win32.Build.0 = Release|Win32
- {C5EC52B2-1E28-4AF1-A244-CBB514C361C0}.Debug Recstore|Win32.ActiveCfg = Debug|Win32
- {C5EC52B2-1E28-4AF1-A244-CBB514C361C0}.Debug Recstore|Win32.Build.0 = Debug|Win32
- {C5EC52B2-1E28-4AF1-A244-CBB514C361C0}.Debug|Win32.ActiveCfg = Debug|Win32
- {C5EC52B2-1E28-4AF1-A244-CBB514C361C0}.Debug|Win32.Build.0 = Debug|Win32
- {C5EC52B2-1E28-4AF1-A244-CBB514C361C0}.release_nojni|Win32.ActiveCfg = Release|Win32
- {C5EC52B2-1E28-4AF1-A244-CBB514C361C0}.release_nojni|Win32.Build.0 = Release|Win32
- {C5EC52B2-1E28-4AF1-A244-CBB514C361C0}.Release|Win32.ActiveCfg = Release|Win32
- {C5EC52B2-1E28-4AF1-A244-CBB514C361C0}.Release|Win32.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/db/jsobj.cpp b/db/jsobj.cpp
index 1b309838db3..c1d87f00cf5 100644
--- a/db/jsobj.cpp
+++ b/db/jsobj.cpp
@@ -1011,7 +1011,7 @@ namespace mongo {
void run() {
testRegex();
BSONObjBuilder A,B,C;
- A.appendInt("x", 2);
+ A.append("x", 2);
B.append("x", 2.0);
C.append("x", 2.1);
BSONObj a = A.done();
@@ -1026,21 +1026,14 @@ namespace mongo {
}
} bson_unittest;
-
-
-
- BSONObjBuilderValueStream::BSONObjBuilderValueStream( const char * fieldName , BSONObjBuilder * builder ) {
- _fieldName = fieldName;
- _builder = builder;
- }
-
+/*
BSONObjBuilder& BSONObjBuilderValueStream::operator<<( const char * value ) {
_builder->append( _fieldName , value );
return *_builder;
}
BSONObjBuilder& BSONObjBuilderValueStream::operator<<( const int value ) {
- _builder->appendInt( _fieldName , value );
+ _builder->append( _fieldName , value );
return *_builder;
}
@@ -1048,6 +1041,7 @@ namespace mongo {
_builder->append( _fieldName , value );
return *_builder;
}
+*/
void OID::init() {
static unsigned machine = (unsigned) security.getNonce();
diff --git a/db/jsobj.h b/db/jsobj.h
index 2e363bb7a06..b2edb64a2f2 100644
--- a/db/jsobj.h
+++ b/db/jsobj.h
@@ -734,11 +734,15 @@ namespace mongo {
public:
BSONObjBuilderValueStream( const char * fieldName , BSONObjBuilder * builder );
+ template<class T>
+ BSONObjBuilder& operator<<( T value );
+/*
BSONObjBuilder& operator<<( const char * value );
BSONObjBuilder& operator<<( const string& v ) { return (*this << v.c_str()); }
BSONObjBuilder& operator<<( const int value );
BSONObjBuilder& operator<<( const double value );
BSONObjBuilder& operator<<( const unsigned long value ){ return (*this << (double)value); }
+*/
private:
const char * _fieldName;
@@ -794,11 +798,12 @@ namespace mongo {
b.append((char) (val?1:0));
}
/** Append a 32 bit integer element */
- void appendInt(const char *fieldName, int n) {
+ void append(const char *fieldName, int n) {
b.append((char) NumberInt);
b.append(fieldName);
b.append(n);
}
+ void append(const char *fieldName, unsigned n) { append(fieldName, (int) n); }
/** Append a double element */
BSONObjBuilder& append(const char *fieldName, double n) {
b.append((char) NumberDouble);
@@ -938,13 +943,13 @@ namespace mongo {
marshalArray( fieldName, arrBuilder.done() );
}
- /** Append an array of ints */
- void appendIntArray( const char *fieldName, const vector< int >& vals ) {
+ /* Append an array of ints
+ void appendArray( const char *fieldName, const vector< int >& vals ) {
BSONObjBuilder arrBuilder;
for ( unsigned i = 0; i < vals.size(); ++i )
- arrBuilder.appendInt( numStr( i ).c_str(), vals[ i ] );
+ arrBuilder.append( numStr( i ).c_str(), vals[ i ] );
marshalArray( fieldName, arrBuilder.done() );
- }
+ }*/
/** The returned BSONObj will free the buffer when it is finished. */
BSONObj obj() {
@@ -1013,6 +1018,9 @@ namespace mongo {
Note each BSONObj ends with an EOO element: so you will get more() on an empty
object, although next().eoo() will be true.
+
+ todo: we may want to make a more stl-like iterator interface for this
+ with things like begin() and end()
*/
class BSONObjIterator {
public:
@@ -1179,4 +1187,15 @@ namespace mongo {
return false;
}
+ inline BSONObjBuilderValueStream::BSONObjBuilderValueStream( const char * fieldName , BSONObjBuilder * builder ) {
+ _fieldName = fieldName;
+ _builder = builder;
+ }
+
+ template<class T> inline
+ BSONObjBuilder& BSONObjBuilderValueStream::operator<<( T value ) {
+ _builder->append(_fieldName, value);
+ return *_builder;
+ }
+
} // namespace mongo
diff --git a/dbtests/jsobjtests.cpp b/dbtests/jsobjtests.cpp
index abcfa3f8047..1199858f97c 100644
--- a/dbtests/jsobjtests.cpp
+++ b/dbtests/jsobjtests.cpp
@@ -36,12 +36,12 @@ namespace JsobjTests {
protected:
static BSONObj basic( const char *name, int val ) {
BSONObjBuilder b;
- b.appendInt( name, val );
+ b.append( name, val );
return b.obj();
}
static BSONObj basic( const char *name, vector< int > val ) {
BSONObjBuilder b;
- b.appendIntArray( name, val );
+ b.append( name, val );
return b.obj();
}
template< class T >
diff --git a/dbtests/jsontests.cpp b/dbtests/jsontests.cpp
index e78d6f29d83..5893d89f83b 100644
--- a/dbtests/jsontests.cpp
+++ b/dbtests/jsontests.cpp
@@ -86,7 +86,7 @@ namespace JsonTests {
public:
void run() {
BSONObjBuilder b;
- b.appendInt( "a", 1 );
+ b.append( "a", 1 );
ASSERT_EQUALS( "{ \"a\" : 1 }", b.done().jsonString( Strict ) );
}
};
diff --git a/dbtests/matchertests.cpp b/dbtests/matchertests.cpp
index 072cced811e..f7a894fc2af 100644
--- a/dbtests/matchertests.cpp
+++ b/dbtests/matchertests.cpp
@@ -47,7 +47,7 @@ namespace MatcherTests {
public:
void run() {
BSONObjBuilder query;
- query.appendInt( "a", 5 );
+ query.append( "a", 5 );
JSMatcher m( query.done(), fromjson( "{\"a\":1}" ) );
ASSERT( m.matches( fromjson( "{\"a\":5}" ) ) );
}
@@ -59,7 +59,7 @@ namespace MatcherTests {
BSONObj query = fromjson( "{\"a\":{\"$gt\":4}}" );
JSMatcher m( query, fromjson( "{\"a\":1}" ) );
BSONObjBuilder b;
- b.appendInt( "a", 5 );
+ b.append( "a", 5 );
ASSERT( m.matches( b.done() ) );
}
};
diff --git a/dbtests/pairingtests.cpp b/dbtests/pairingtests.cpp
index 27d92a9b932..b19ed8ec98e 100644
--- a/dbtests/pairingtests.cpp
+++ b/dbtests/pairingtests.cpp
@@ -175,8 +175,8 @@ namespace PairingTests {
private:
BSONObj res( int ok, int youAre ) {
BSONObjBuilder b;
- b.appendInt( "ok", ok );
- b.appendInt( "you_are", youAre );
+ b.append( "ok", ok );
+ b.append( "you_are", youAre );
return b.obj();
}
};