【问题标题】:What's Returned on find in Mongo Mapper?Mongo Mapper 中的返回结果是什么?
【发布时间】:2013-01-17 13:16:05
【问题描述】:

我正在根据文档的 id 在集合中搜索文档。

如果找不到find(the_id),返回什么?

session[:remote_ip] =  request.env['REMOTE_ADDR'].split(',').first
user = User.find({user_id: session[:remote_ip]})
if user.nil?
  # Do stuff if find couldn't find the user_id
  # Am I right to assume it will return nil?

【问题讨论】:

    标签: ruby mongodb mongomapper


    【解决方案1】:

    绝对!

    如您所见,它甚至还有一个规范:

    https://github.com/jnunemaker/mongomapper/blob/master/test/functional/test_querying.rb#L183

    也试试 Mongoid。

    这是 MongoDB 的另一个伟大之处: https://github.com/mongoid/mongoid

    【讨论】:

    • 谢谢。我应该考虑看看规范。 Mongoid 也在我的学习清单上:)
    猜你喜欢
    • 2019-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-15
    • 1970-01-01
    相关资源
    最近更新 更多