顾名思义,我想获取客户端连接到的mongo实例的版本。目前,我正在使用mongo java驱动程序2.9.3,而mongo实例是2.2.2。
我需要这个,为了支持$pushAll
和$push
使用$each
功能的,因为前者是从2.4版本赞成后者弃用。简而言之,我想知道等效于Java驱动程序db.version()
稍微戳一下便发现:
> db.version()
2.4.6
> db.version
function (){
return this.serverBuildInfo().version;
}
> db.serverBuildInfo
function (){
return this._adminCommand( "buildinfo" );
}
> db.runCommand('buildinfo')
{
"version" : "2.4.6",
"gitVersion" : "b9925db5eac369d77a3a5f5d98a145eaaacd9673",
"sysInfo" : "Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49",
"loaderFlags" : "-fPIC -pthread -rdynamic",
"compilerFlags" : "-Wnon-virtual-dtor -Woverloaded-virtual -fPIC -fno-strict-aliasing -ggdb -pthread -Wall -Wsign-compare -Wno-unknown-pragmas -Winvalid-pch -Werror -pipe -fno-builtin-memcmp -O3",
"allocator" : "tcmalloc",
"versionArray" : [
2,
4,
6,
0
],
"javascriptEngine" : "V8",
"bits" : 64,
"debug" : false,
"maxBsonObjectSize" : 16777216,
"ok" : 1
}
因此,您只可以runCommand
在Java代码中使用等效项(不知道Java驱动程序,我是ruby guy)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句