[英]in Robo3T, how to add a custom function
I just installed Robo3T( previously named robomongo), which has a GUI for mongo db.我刚刚安装了 Robo3T(以前命名为 robomongo),它有一个用于 mongo db 的 GUI。 I want to add a custom function to help me get the last N documents in normal order, the query statement is like this:
我想添加一个自定义函数,帮助我按正常顺序获取最后N个文档,查询语句是这样的:
db.getCollection('i1801').find().skip(db.getCollection('i1801').count() - 1200)
And I found from stackoverflow( mongodb: how to get the last N records? ), this can be written as a function like this:我从 stackoverflow( mongodb: how to get the last N records? ) 中发现,这可以写成这样的函数:
function last(N) {
return db.collection.find().skip(db.collection.count() - N);
}
And I go back to my Robo3T, trying to add a custom function last()
, but didn't work, nothing showed up under function tab.然后我回到我的 Robo3T,尝试添加一个自定义函数
last()
,但没有用,函数选项卡下没有显示任何内容。
I have attached some screen captures illustrating this issue:我附上了一些说明此问题的屏幕截图:
After I clicked save button, nothing happened, still no functions under function tab.单击保存按钮后,什么也没发生,功能选项卡下仍然没有任何功能。 And the log shows function
last
created, and function tab being refreshed.并且日志显示
last
创建的功能,以及正在刷新的功能选项卡。
So, how can I add a last
function here?那么,如何在此处添加
last
函数?
Tried the steps you listed, it worked for simple find statements.尝试了您列出的步骤,它适用于简单的查找语句。 When I added the 'skip', the save failed.
当我添加“跳过”时,保存失败。 Even updating an existing function didn't work.
即使更新现有功能也不起作用。 Maybe an issue with Robo?
也许是 Robo 的问题? I dont know.
我不知道。
Anyway, to add the function in Robo3t无论如何,在Robo3t中添加功能
db.system.js.save( { _id: "last", value : function last(x) { return db.test.find().skip(db.test.count() - x); } } )
Lastly, Run the script and refresh Function folder.最后,运行脚本并刷新 Function 文件夹。
For calling function:对于调用函数:
db.loadServerScripts();
db.loadServerScripts();
callyourfunction();调用你的函数();
NOTE :: For seen output, Make sure your function should be a return value注意 :: 对于可见的输出,请确保您的函数应该是返回值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.