mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
option to appendOID to gen _id
This commit is contained in:
parent
46e9226668
commit
0c0a3893e4
@ -1152,14 +1152,17 @@ namespace mongo {
|
||||
}
|
||||
|
||||
/** Append a BSON Object ID (OID type). */
|
||||
void appendOID(const char *fieldName, OID *oid = 0) {
|
||||
void appendOID(const char *fieldName, OID *oid = 0 , bool gen = false ) {
|
||||
b.append((char) jstOID);
|
||||
b.append(fieldName);
|
||||
if ( oid )
|
||||
b.append( (void *) oid, 12 );
|
||||
else {
|
||||
OID tmp;
|
||||
memset( &tmp, 0, 12 );
|
||||
if ( gen )
|
||||
tmp.init();
|
||||
else
|
||||
memset( &tmp, 0, 12 );
|
||||
b.append( (void *) &tmp, 12 );
|
||||
}
|
||||
}
|
||||
|
@ -579,6 +579,22 @@ namespace JsobjTests {
|
||||
ASSERT( a == b );
|
||||
}
|
||||
};
|
||||
|
||||
class append {
|
||||
public:
|
||||
void run(){
|
||||
BSONObjBuilder b;
|
||||
b.appendOID( "a" , 0 );
|
||||
b.appendOID( "b" , 0 , false );
|
||||
b.appendOID( "c" , 0 , true );
|
||||
BSONObj o = b.obj();
|
||||
|
||||
ASSERT( o["a"].__oid().str() == "000000000000000000000000" );
|
||||
ASSERT( o["b"].__oid().str() == "000000000000000000000000" );
|
||||
ASSERT( o["c"].__oid().str() != "000000000000000000000000" );
|
||||
|
||||
}
|
||||
};
|
||||
} // namespace OIDTests
|
||||
|
||||
namespace ValueStreamTests {
|
||||
@ -834,6 +850,7 @@ namespace JsobjTests {
|
||||
add< BSONObjTests::Validation::Fuzz >( .001 );
|
||||
add< OIDTests::init1 >();
|
||||
add< OIDTests::initParse1 >();
|
||||
add< OIDTests::append >();
|
||||
add< ValueStreamTests::LabelBasic >();
|
||||
add< ValueStreamTests::LabelShares >();
|
||||
add< ValueStreamTests::LabelDouble >();
|
||||
|
Loading…
Reference in New Issue
Block a user