Questions tagged [mongoid]

Mongoid is the official Ruby Object-Document-Mapper (ODM) for MongoDB.

Mongoid (pronounced mann-goyd) is an Object-Document-Mapper (ODM) for MongoDB written in Ruby. Mongoid as of version 5 is under the control and guidance of MongoDB as the official Ruby ODM.

The philosophy of Mongoid is to provide a familiar API to Ruby developers who have been using Active Record or Data Mapper, while leveraging the power of MongoDB's schema-less and performant document-based design, dynamic queries, and atomic modifier operations.

4728 questions
16
votes
3 answers

Why is_a? returns false for Hash class?

Why is_a? returns false for a Hash class? Example: value = {"x" => 3, "y" => 2} puts value.class puts value.is_a?(Hash) Output: Hash false Im using Ruby 1.9.2 UPDATED: full source of my class: class LatLng include…
Alexey Zakharov
  • 24,694
  • 42
  • 126
  • 197
16
votes
4 answers

mongoid query caching

Rails' ActiveRecord has a feature called Query Caching (ActiveRecord::QueryCache) which saves the result of SQL query for the life-span of a request. While I'm not very familiar with the internals of the implementation, I think that it saves the…
Roman
  • 13,100
  • 2
  • 47
  • 63
16
votes
2 answers

mongoid multi parameter attributes problem with date

I have been following the mongoid railscast and I am facing a multi parameter attributes problem when i add a new field field :published_on, :type => Date Article.find("4da14b1447640b14eb000002").published_on => nil but with…
wizztjh
  • 6,979
  • 6
  • 58
  • 92
16
votes
1 answer

field_for and nested form with mongoid

Could somebody give me the working example of nested form using mongoid? My models: class Employee include Mongoid::Document field :first_name field :last_name embeds_one :address end class Address include Mongoid::Document field…
Kir
  • 7,981
  • 12
  • 52
  • 69
16
votes
3 answers

Rails: Store JSON in MongoDB

I am getting multiple similar JSON object from a remote site and looking to store them in a local MongoDB. What would be the best way to do this ? (Preferably via Mongoid or Mongo-mapper gems) Thanks
Boris
  • 3,163
  • 5
  • 37
  • 46
16
votes
2 answers

How to get last N documents with mongoid?

I have found some information to accomplish this in mongoDB, but I need it with mongoid. So I can do something like: User.last(7000).each do .... I'm using: MongoDB shell version: 2.4.3 Mongoid 2.6.0 Thanks!
cortex
  • 5,036
  • 3
  • 31
  • 41
16
votes
1 answer

MongoID find or find_by

The MongoID docs seem to be pretty clear that I should be able to run this and have it work: Band.find_by(name: "Photek") but at least with MongoID 2.4.11 this gives me a NoMethodError. This, on the other hand, works: Band.find(name:…
Leopd
  • 41,333
  • 31
  • 129
  • 167
15
votes
2 answers

Mongoid dependent :destroy vs :delete

When using Mongoid referenced reletions what's the diffrence between dependent detroy and dependent delete since in the docs it tells: :delete: Delete the child documents. :destroy: Destroy the child documents.
Matteo Pagliazzi
  • 5,140
  • 12
  • 49
  • 83
15
votes
2 answers

In a MongoDB query, what does a negative limit mean?

I'm using the Mongoid ruby gem to interact w/ MongoDB and when I try to get one of something from a query, it adds $limit: -1 (i.e. negative one) when I would expect it to just use 1. I tried doing the same thing in the console and it didn't change…
nicholaides
  • 19,211
  • 12
  • 66
  • 82
15
votes
3 answers

MongoDB with Mongoid in Rails - Geospatial Indexing

MongoDB has a very nice Geospatial Indexing feature. How can I use it in Rails with Mongoid?
CamelCamelCamel
  • 5,200
  • 8
  • 61
  • 93
15
votes
5 answers

How do I validate members of an array field?

I have this model: class Campaign include Mongoid::Document include Mongoid::Timestamps field :name, :type => String field :subdomain, :type => String field :intro, :type => String field :body, :type => String field :emails, :type =>…
Antonio Pardo
  • 189
  • 2
  • 2
  • 7
15
votes
4 answers

Rails/Mongoid error messages in nested attributes

I have a contact info class defined like this: class ContactInfo include Mongoid::Document validates_presence_of :name, :message => ' cannot be blank' field :name, :type => String field :address, :type => String field :city, :type =>…
Richard
  • 1,146
  • 1
  • 13
  • 24
15
votes
2 answers

Disable mongoid belongs_to association validation

A have two mongoid models with a simple has_many/belongs_to relationship between them: class Lot include Mongoid::Document has_many :journal_items end class JournalItem include Mongoid::Document belongs_to :lot end The issue is that I…
Dmitry Sokurenko
  • 6,042
  • 4
  • 32
  • 53
15
votes
4 answers

heroku mongohq and mongoid Mongo::ConnectionFailure

UPDATE 9th june 2012: Setup with mongoid 3.0.0.rc at heroku, see this gist: https://gist.github.com/2900804 UPDATE 22th jan 2011: Uri now takes precedence in mongoid.yml https://github.com/mongoid/mongoid/issues/issue/266 UPDATE 12th aug 2010:…
oma
  • 38,642
  • 11
  • 71
  • 99
15
votes
4 answers

Dynamic attributes with Rails and Mongoid

I'm learning MongoDB through the Mongoid Ruby gem with Rails (Rails 3 beta 3), and I'm trying to come up with a way to create dynamic attributes on a model based on fields from another model, which I thought a schema-less database would be a good…
joeellis
  • 2,745
  • 7
  • 28
  • 45