如何使用 MongoMapper/Ruby 进行查询?
我开始将 NoSQL 与 Ruby 结合使用。这是我的代码
require 'mongo'
require 'mongo_mapper'
class User
include MongoMapper::Document
end
MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
MongoMapper.database = "mydb"
all_users = MongoUser.where(:age => 1) # WORKS
all_users = MongoUser.where("age > 1") # DOESN'T WORK
如何使用 ActiveRecord 之类的查询?当我需要在查询中使用<、>、!=等时我需要做什么?
I started using NoSQL with Ruby. Here's the code I have
require 'mongo'
require 'mongo_mapper'
class User
include MongoMapper::Document
end
MongoMapper.connection = Mongo::Connection.new('localhost', 27017)
MongoMapper.database = "mydb"
all_users = MongoUser.where(:age => 1) # WORKS
all_users = MongoUser.where("age > 1") # DOESN'T WORK
How can I use ActiveRecord's like where querying? What do I need to do when I need to use <, >, != etc in queries?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
试试这个:
try this:
从此处开始阅读。 Mongomapper 建立在 Datamapper 理念之上,因此如果您想要更接近 ActiveRecord 的东西,请尝试 Mongoid。
Start to read here. Mongomapper is build on Datamapper philosophy, so if you want something closer to ActiveRecord try Mongoid.