前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Ruby 操作 MongoDB(1)

Ruby 操作 MongoDB(1)

作者头像
franket
发布2021-10-19 11:50:49
4230
发布2021-10-19 11:50:49
举报
文章被收录于专栏:技术杂记

前言

使用 Ruby 处理各种任务时难免会和数据库打交道,而 MongoDB 又是一款应用极其广泛的数据库

RubyGems 是 Ruby 的武器库,类似于 Perl 的 CPAN,各类封装好的处理逻辑应有尽有,我们可以充分利用这些成品包来减轻开发的工作量,其中 mongo 的 gem 就可以很好地满足我们的需求

A Ruby driver for MongoDB

The MongoDB Ruby driver is the officially supported Ruby driver for MongoDB. It’s written in pure Ruby and is optimized for simplicity. It can be used on its own, but it also serves as the basis of several object mapping libraries

这里我分享一下使用 Ruby 来操作 MongoDB 数据库的相关基础,详细可以参考 Ruby Driver Tutorial

Tip: 当前的最新版本为 mongo 2.2.5


概要


环境

代码语言:javascript
复制
[root@h102 ~]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m

[root@h102 ~]# uname -a 
Linux h102.temp 2.6.32-504.el6.x86_64 #1 SMP Wed Oct 15 04:27:16 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@h102 ~]# ruby -v 
ruby 2.3.0p0 (2015-12-25 revision 53290) [x86_64-linux]
[root@h102 ~]#

安装 mongo

代码语言:javascript
复制
[root@h102 ~]# gem source -l 
*** CURRENT SOURCES ***

https://gems.ruby-china.org
[root@h102 ~]# gem install mongo
Fetching: bson-4.1.1.gem (100%)
Building native extensions.  This could take a while...
Successfully installed bson-4.1.1
Fetching: mongo-2.2.5.gem (100%)
Successfully installed mongo-2.2.5
Parsing documentation for bson-4.1.1
Installing ri documentation for bson-4.1.1
Parsing documentation for mongo-2.2.5
Installing ri documentation for mongo-2.2.5
Done installing documentation for bson, mongo after 8 seconds
2 gems installed
[root@h102 ~]# gem list | grep mongo
mongo (2.2.5)
[root@h102 ~]#

Tip: 确认一下安装源,否则可能被墙,速度慢得没法忍


兼容性

不同版本 MongoDB

下面这张表是不同版本 Ruby Driver 与不同版本 MongoDB 的兼容性列表

Ruby Driver

MongoDB 2.4

MongoDB 2.6

MongoDB 3.0

MongoDB 3.2

2.2

2.0

1.12

不同版本 Ruby 语言

下面这张表是不同版本 Ruby Driver 与不同版本 Ruby 语言的兼容性列表

Ruby Driver

Ruby 1.8.7

Ruby 1.9

Ruby 2.0

Ruby 2.1

JRuby

2.0

1.9

本文系转载,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文系转载前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 前言
  • 概要
    • 环境
      • 安装 mongo
        • 兼容性
          • 不同版本 MongoDB
          • 不同版本 Ruby 语言
      相关产品与服务
      云数据库 MongoDB
      腾讯云数据库 MongoDB(TencentDB for MongoDB)是腾讯云基于全球广受欢迎的 MongoDB 打造的高性能 NoSQL 数据库,100%完全兼容 MongoDB 协议,支持跨文档事务,提供稳定丰富的监控管理,弹性可扩展、自动容灾,适用于文档型数据库场景,您无需自建灾备体系及控制管理系统。
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档