轻便摩托车:运行裸体mongo命令

时间:2014-02-17 14:48:07

标签: mongodb moped

中运行stat命令时,我没有收到此类命令错误 mongo控制台中的

db.stat()

但是从轻便摩托车运行它会产生错误

session.command(stat: 1)

failed with error "no such cmd: stat"

1 个答案:

答案 0 :(得分:3)

mongo控制台命令是" stats" (不是" stat")并在此处记录。

http://docs.mongodb.org/manual/reference/method/db.stats/

详细说明,

db.stats()方法是dbStats数据库命令的包装器。

http://docs.mongodb.org/manual/reference/command/dbStats/#dbcmd.dbStats

所以这是一个显示轻便摩托车用途的测试。

test.rb

require 'moped'
require 'test/unit'
require 'pp'

class MyTest < Test::Unit::TestCase

  def setup
    @session = Moped::Session.new([ "127.0.0.1:27017" ])
    @session.use "test"
  end

  test "db stats" do
    puts "Moped::VERSION:#{Moped::VERSION}"
    dbstats =  @session.command(dbstats: 1)
    assert_equal("test", dbstats["db"])
    pp dbstats
  end
end

ruby​​ test.rb

Loaded suite test
Started
Moped::VERSION:1.5.2
{"db"=>"test",
 "collections"=>3,
 "objects"=>5,
 "avgObjSize"=>99.2,
 "dataSize"=>496,
 "storageSize"=>24576,
 "numExtents"=>3,
 "indexes"=>1,
 "indexSize"=>8176,
 "fileSize"=>67108864,
 "nsSizeMB"=>16,
 "dataFileVersion"=>{"major"=>4, "minor"=>5},
 "extentFreeList"=>{"num"=>0, "totalSize"=>0},
 "ok"=>1.0}
.

Finished in 0.005335 seconds.

1 tests, 1 assertions, 0 failures, 0 errors, 0 pendings, 0 omissions, 0 notifications
100% passed

187.44 tests/s, 187.44 assertions/s