MongoDB:未在数据库上授权执行命令eval

时间:2018-05-16 13:08:52

标签: mongodb mongodb-query database-administration rbac

这是我正在运行的查询:

nodemap = {--I've used small field for debugging
  {1,1,1,1,1,1,1},
  {1,0,0,0,0,0,1},
  {1,0,1,0,1,1,1},
  {1,0,0,0,1,1,1},
  {1,1,1,1,1,1,1},
}

mrspacman={dz=0,dir=false,x=2,y=2,speed=0.1,nextDirection=false}

local dlog=function(...)--debug function
  print(string.format(...))
end

math2 = {
    cos = function(angle)
        vectors = {1,0,-1,0}--this would be better of by being a local variable
        return vectors[(angle/90)+1]
    end,

    sin = function(angle)
        vectors = {0,1,0,-1}--this too
        return vectors[(angle/90)+1]
    end
}


local graphic_lines={}
for _,line in ipairs(nodemap) do
  local l=table.concat(line):gsub("0"," ")
  table.insert(graphic_lines,l)
end

local time_step=1
function draw()--quick and dirty output to terminal
  print(string.format("\nStep %i",time_step))
  time_step=time_step+1
  local x,y = mrspacman.x,mrspacman.y
  local px,py=math.floor(x+0.5),math.floor(y+0.5)
  for index,line in ipairs(graphic_lines) do
    if index~= py then 
      print(line) 
    else
      print( line:sub(1,px-1) .. "@" .. line:sub(px+1))
    end
  end
  print(string.format('Real position (x,y): (%f , %f)',x,y))
  print(string.format('Current direction: %i',mrspacman.dz))
  if mrspacman.nextDirection then
    print(string.format("Trying to turn at %i",mrspacman.dir or "error"))
  end
end


local inputs={--i've mixed up directions due to my renderer
  w=90,
  a=180,
  s=270,
  d=0,
}
local skips={['']=true,[' ']=true}

function input(macro_input)--read wasd from terminal
  print('your move')
  local key= (macro_input and macro_input()) or io.read();
  if skips[key] then return end
  local dir = inputs[key];
  if not dir then print('wrong key') return end
  mrspacman.dir = dir
  mrspacman.nextDirection=true
end

function sim_step()
dlog('"Smoothing" (%f,%f) through (%f,%f) to (%f,%f)',mrspacman.x,mrspacman.y,mrspacman.x*10,mrspacman.y*10,math.floor(mrspacman.x*10)/10,math.floor(mrspacman.y*10)/10)
dlog('"Fixing smoothing" (%f,%f) through (%f,%f) to (%f,%f)',mrspacman.x,mrspacman.y,(mrspacman.x+0.05)*10,(mrspacman.y+0.05)*10,math.floor((mrspacman.x+0.05)*10)/10,math.floor((mrspacman.y+0.05)*10)/10)

mrspacman.x = math.floor(mrspacman.x*10+.5)/10--these lines are different
mrspacman.y = math.floor(mrspacman.y*10+.5)/10--

--If an arrowkey was pressed (Think of this as "A new direction was queued")
if (mrspacman.nextDirection) then
    dlog("trying to turn")
    -- If Pacman is in the center of a tile, then
    if (mrspacman.x == math.floor(mrspacman.x)) and (mrspacman.y == math.floor(mrspacman.y)) then
        dlog("Pacman is in the center of a tile")
        -- If the tile in front of Pacman is empty, set direction to that
        dlog("lookup dy: %f dx: %f",-math2.sin(mrspacman.dir),math2.cos(mrspacman.dir))
        dlog("lookup y: %f x: %f",mrspacman.y-math2.sin(mrspacman.dir),mrspacman.x+math2.cos(mrspacman.dir))
        dlog(nodemap[mrspacman.y-math2.sin(mrspacman.dir)][mrspacman.x+math2.cos(mrspacman.dir)]==1 and "Its a wall" or "")
        if (nodemap[mrspacman.y-math2.sin(mrspacman.dir)][mrspacman.x+math2.cos(mrspacman.dir)]~=1) then
            dlog("turning")
            mrspacman.dz = mrspacman.dir

            -- Disable this queue
            mrspacman.nextDirection = false
          else
            dlog"not turning"
        end
    end
end

-- If Pacman is NOT in the center of a tile
if (mrspacman.x ~= math.floor(mrspacman.x)) or (mrspacman.y ~= math.floor(mrspacman.y)) then
    dlog("Pacman is NOT in the center of a tile, moving with no collision check")
    -- Constantly move forwards
    dlog("deltaX, deltaY : %f, %f",(math2.cos(mrspacman.dz)*mrspacman.speed),-(math2.sin(mrspacman.dz)*mrspacman.speed))
    dlog("before (%f, %f)",mrspacman.x,mrspacman.y)
    mrspacman.x = mrspacman.x + (math2.cos(mrspacman.dz)*mrspacman.speed)
    mrspacman.y = mrspacman.y - (math2.sin(mrspacman.dz)*mrspacman.speed)
    dlog("after (%f, %f)",mrspacman.x,mrspacman.y)
else
    dlog("moving with collision check")
    -- If the tile in front of Pacman is empty, move to that tile
    if (nodemap[mrspacman.y-math2.sin(mrspacman.dz)][mrspacman.x+math2.cos(mrspacman.dz)] ~= 1) then
        dlog("can move")
        mrspacman.x = mrspacman.x + (math2.cos(mrspacman.dz)*mrspacman.speed)
        mrspacman.y = mrspacman.y - (math2.sin(mrspacman.dz)*mrspacman.speed)
    else
        dlog("hit wall")
    end
end

end


local gen_macro = function(sequence)--function generating predefined set of keypresses
  sequence=sequence or ""
  local step=0
  return function()
    step=step+1
    if (step>sequence:len()) then return end--return to manual control
    return sequence:sub(step,step)
  end
end

local simple_macro= function() return gen_macro("wasd") end--simple sample, "--will do nothing
local horizontal_bend = function()--will bring pacman to bottom left
  local _x10=string.rep(" ",10);
  local sequence=_x10:rep(2).."s".._x10:rep(2).."a".._x10:rep(2)
  return gen_macro(sequence)
end

local angry_monkey=function(length)--gen random sequence of buttons
  length=length or 0
  local keys={"a","s","d","w"," "}
  local seq = {}
  for i=1,length do
    table.insert(seq,keys[math.random(#keys)])
  end
  return gen_macro(table.concat(seq))
end

local macro
--macro=simple_macro()
--macro=horizontal_bend()
--macro = angry_monkey(100)

--dlog=function() end --uncomment this to disable debug

while true do
  draw()
  input(macro)
  sim_step()
--  if time_step>10 then return end
end

我收到错误:

db.surveyquestion.copyTo('surveyquestionV2')

我在用于运行此查询的admin db中的用户:

{
    "message" : "MongoError: not authorized on GenericSurveyTool to execute command { $eval: function (collName, newName) {\r" +
              "var from = db[collName];\r" +
              "..., args: [ 'surveyquestion', 'surveyquestionV2' ], $db: 'GenericSurveyTool' }",
    "stack" : "script:1:19",
    "code" : 13
}

我有这个用户具有root角色,但我仍然无法复制集合。请帮忙!!

1 个答案:

答案 0 :(得分:6)

对于遇到相同问题的人,解决方案在db.eval()的文档中:just right here

  

如果启用了授权,则必须有权访问所有资源上的所有操作才能运行eval。建议不要提供此类访问权限,但如果您的组织要求用户运行eval,请创建一个在anyResource上授予anyAction的角色。不要将此角色分配给任何其他用户。