MongoDb使用c++;司机 P>有没有使用MunGDB(2.2)C++驱动程序创建索引的方法?
MongoDb使用c++;司机 P>有没有使用MunGDB(2.2)C++驱动程序创建索引的方法?,c++,mongodb,indexing,mongo-cxx-driver,C++,Mongodb,Indexing,Mongo Cxx Driver,ensureIndex函数似乎不接受此参数。发件人: 就这点而言,这也不是一个论点 作为一种解决方法,您可以自己构建服务器命令并附加sparse参数。如果您遵循,您会注意到server命令包括构建一个BSONObject,并且各种索引选项作为字段附加。编写自己版本的ensureIndex应该很简单,我最后修补了Mongo源代码(Mongo/cleint/dbclient.cpp): 问题应该在2.3.2版中出现,似乎在构建过程中使用的一些变量是私有的,不能在类外修改。最后我修补了C++驱动程序代
ensureIndex
函数似乎不接受此参数。发件人:
就这点而言,这也不是一个论点
作为一种解决方法,您可以自己构建服务器命令并附加
sparse
参数。如果您遵循,您会注意到server命令包括构建一个BSONObject
,并且各种索引选项作为字段附加。编写自己版本的ensureIndex
应该很简单,我最后修补了Mongo源代码(Mongo/cleint/dbclient.cpp
):
问题应该在2.3.2版中出现,似乎在构建过程中使用的一些变量是私有的,不能在类外修改。最后我修补了C++驱动程序代码。
bool mongo::DBClientWithCommands::ensureIndex(
const string & ns,
BSONObj keys,
bool unique = false,
const string & name = "",
bool cache = true,
bool background = false,
int v = -1)
bool DBClientWithCommands::ensureIndex( const string &ns , BSONObj keys , bool unique, const string & name , bool cache, bool background, int version, bool sparse ) {
BSONObjBuilder toSave;
toSave.append( "ns" , ns );
toSave.append( "key" , keys );
string cacheKey(ns);
cacheKey += "--";
if ( name != "" ) {
toSave.append( "name" , name );
cacheKey += name;
}
else {
string nn = genIndexName( keys );
toSave.append( "name" , nn );
cacheKey += nn;
}
if( version >= 0 )
toSave.append("v", version);
if ( unique )
toSave.appendBool( "unique", unique );
if ( sparse )
toSave.appendBool( "sparse", true );
if( background )
toSave.appendBool( "background", true );
if ( _seenIndexes.count( cacheKey ) )
return 0;
if ( cache )
_seenIndexes.insert( cacheKey );
insert( Namespace( ns.c_str() ).getSisterNS( "system.indexes" ).c_str() , toSave.obj() );
return 1;
}