在Windows上使用ROR和MongoDB

本文涉及的产品
云数据库 MongoDB,独享型 2核8GB
推荐场景:
构建全方位客户视图
简介:          Ruby和MongoDB在Linux上结合非常自然,开发起来十分方便快捷,而在Windows上却稍微有些麻烦。         ROR默认使用ActiveRecord进行数据库操作,而如果要使用MongoDB代替MySQL或者SQLite,就要禁用ActiveRecord。

         Ruby和MongoDB在Linux上结合非常自然,开发起来十分方便快捷,而在Windows上却稍微有些麻烦。

         ROR默认使用ActiveRecord进行数据库操作,而如果要使用MongoDB代替MySQL或者SQLite,就要禁用ActiveRecord。那么创建新项目的命令就是:

rails new watermelon --skip-active-record

项目创建后,进入config目录,可以看到里面并没有database.yml文件。接着编辑Gemfile,添加下面两行内容:

source 'http://gemcutter.org'

gem 'mongo_mapper'

然后运行

bundle install

会安装:bson 1.3.1,mongo 1.3.1,plucky 0.3.8和mongo_mapper 0.9.1。除了这些之外,还需要bson_ext,于是就想通过

gem install bson_ext

进行安装,可是得到了下面的错误信息:

         从提示信息中可以看出需要安装一个开发工具包。步骤如下:

         1. 在RubyInstaller for Windows的下载页面上http://rubyinstaller.org/downloads找到DevKit-tdm-32-4.5.1-20101214-1400-sfx.exe,直接点击下载;

         2. 下载完成后,双击解压到某个目录下,例如:C:/work/tools/DevKit

         3. 在命令行窗口下进入到C:/work/tools/DevKit目录下,运行

ruby dk.rb init
在C:/work/tools/DevKit下会产生一个config.yml文件,

         4. 编辑config.yml文件,初始内容类似:

# This configuration file contains the absolute path locations of all
# installed Rubies to be enhanced to work with the DevKit. This config
# file is generated by the 'ruby dk.rb init' step and may be modified
# before running the 'ruby dk.rb install' step. To include any installed
# Rubies that were not automagically discovered, simply add a line below
# the triple hyphens with the absolute path to the Ruby root directory.
#
# Example:
#
# ---
# - C:/ruby19trunk
# - C:/ruby192dev
#
在其中加入Ruby的安装目录,如:

---
- C:/work/tools/Ruby192

      5. 运行

ruby dk.rb install
相应的文件就安装C:/work/tools/Ruby192/lib/ruby/site_ruby下面。

     经过上面几步就完成了DevKit的安装,然后就可以通过

gem install bson_ext --platform=ruby

安装bson_ext。

      环境配置完成后,就可以进入ROR和MongoDB相结合的开发了。


      参考资料:

      MongoDB Ruby Driver Tutorial

      MongoDB  Ruby Language Center Rails3 - Getting - Started

      Ruby Installer Development Kit


目录
相关文章
|
5月前
|
NoSQL IDE MongoDB
Studio 3T 2025.11 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.11 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
350 3
|
2月前
|
NoSQL IDE MongoDB
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
259 1
Studio 3T 2025.17 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
5月前
|
NoSQL IDE MongoDB
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
436 21
Studio 3T 2025.10 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
8月前
|
NoSQL IDE MongoDB
Studio 3T 2025.5 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.5 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
325 2
Studio 3T 2025.5 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
8月前
|
NoSQL IDE MongoDB
Studio 3T 2025.4 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
Studio 3T 2025.4 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
321 0
Studio 3T 2025.4 (macOS, Linux, Windows) - MongoDB 的终极 GUI、IDE 和 客户端
|
存储 NoSQL MongoDB
MongoDB入门级别教程全(Windows版,保姆级教程)
一份全面的MongoDB入门级教程,包括在Windows系统上安装MongoDB、使用MongoDB Shell和Compass GUI进行数据库操作,以及MongoDB的基本数据类型和查询技巧。
2842 2
MongoDB入门级别教程全(Windows版,保姆级教程)
|
NoSQL Shell MongoDB
Windows 平台安装 MongoDB
10月更文挑战第10天
383 0
Windows 平台安装 MongoDB
|
存储 JSON NoSQL
【MongoDB】<文档型数据库>Windows&Liunx安装MongoDB(无错完整)
【1月更文挑战第26天】【MongoDB】<文档型数据库>Windows&Liunx安装MongoDB(无错完整)
|
NoSQL MongoDB 数据库
MongoDB【部署 03】Windows系统安装mongodb并设置用户名密码(无需安装mongosh)及SpringBoot集成报错 Command failed with error 18
MongoDB【部署 03】Windows系统安装mongodb并设置用户名密码(无需安装mongosh)及SpringBoot集成报错 Command failed with error 18
1906 0
|
存储 JSON NoSQL
4.0版本以上mongodb在Windows下载安装-添加Windows服务-安装可视化工具管理数据教程
4.0版本以上mongodb在Windows下载安装-添加Windows服务-安装可视化工具管理数据教程
371 0
4.0版本以上mongodb在Windows下载安装-添加Windows服务-安装可视化工具管理数据教程

热门文章

最新文章

推荐镜像

更多