如何从Rails应用程序上的ruby获取mongodb数据库列表和集合列表

编程入门 行业动态 更新时间:2024-10-24 01:52:11
本文介绍了如何从Rails应用程序上的ruby获取mongodb数据库列表和集合列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在使用Rails 3和Mongoid宝石.但是我需要用mongodb数据库列表填充组合框.在mongodb shell中,我们可以使用"show dbs"命令列出数据库.在mongodb驱动程序中,还有getDBNameList()和db.getCollectionNames()命令.但是我不知道如何从Rails应用程序的ruby中使用这些命令.

I am using Rails 3 and Mongoid gem. But I need to fill a combobox with the list of mongodb databases. In mongodb shell we can list databases with "show dbs" command. Also there is getDBNameList() and db.getCollectionNames() commands in mongodb drivers. But I could not figure out how to use these commands from a ruby on rails app.

我也想知道;如果我可以使用mongoid gem获得数据库和收藏夹列表.因为我确信我已经读过mongoid支持使用多个数据库,但是我认为它与模型有关.

Also I wonder; if I can get databases and collections list with using mongoid gem. Because I am sure that I had read that mongoid supports using more than one database, but I think it was model dependent.

那你怎么看?有什么解决办法吗,或者我必须使用mongo-ruby-driver gem,而不是mongoid.

So what do you think; is there any solution or I have to use mongo-ruby-driver gem, not mongoid.

推荐答案

在Mongoid 3中

In mongoid 3

Mongoid.default_session.collections # returns the collections

我通常按以下方式提取名称:

I usually extract the names as follows:

Mongoid.default_session.collections.map(&:name).sort

更多推荐

如何从Rails应用程序上的ruby获取mongodb数据库列表和集合列表

本文发布于:2023-10-25 22:15:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1528260.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:列表   应用程序   数据库   Rails   mongodb

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!