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
2
votes
2 answers

Mongoid persistance issue

I'm trying to assign an attribute in my Rails app, however, the assigned data disappears when I re-query the database. Here are my models: class Scent include Mongoid::Document field :scentid, type: Integer field :name field :price field…
pudding
  • 125
  • 1
  • 9
2
votes
1 answer

Incremental MapReduce with time interval in mongoDB

i got some records from server with time interval of 10 minute (in 1 hours i will get 6 files) i want to do map reduce on every 1 hours in next hours i will have to do map reduce of next group on 6 files with last hours file how i will solve this…
2
votes
3 answers

mongoimport doesn't import the object properly

In Mongodb v2.2 When I try to import one simple json document file like this from my .json file into an empty collection I get 13 objects imported. Here is what I'm doing. this is the data (I've shortened the field names to protect data): [ { …
Roman
  • 10,309
  • 17
  • 66
  • 101
2
votes
1 answer

How do i cascade save a has_and_belongs_to_many relationship with mongoid?

I have a Tag and a Question class. class Question include Mongoid::Document include Mongoid::Timestamps identity type: String has_and_belongs_to_many :tags # Refer to tag_ids end class Tag include Mongoid::Document identity type: String…
Kamilski81
  • 14,409
  • 33
  • 108
  • 161
2
votes
1 answer

Mongoid gives uninitialized constant Mongo

I'm trying to use mongoid but it outputs this error: uninitialized constant 'Mongo' Here is my code: require "mongoid" Mongoid.configure do |config| config.master = Mongo::Connection.new("localhost",27017).db("arthist") end class Artist …
nobinobiru
  • 792
  • 12
  • 28
2
votes
2 answers

ActiveModel validate attribute based on association

I have at least 2 classes. One class must validate one of its attributes based on the value of an associated model's attributes. The below code is what I am going for, but its just an idea, it doesn't work. Any way to achieve it? class Concert …
chris
  • 6,653
  • 6
  • 41
  • 54
2
votes
1 answer

Mongoid Embedded Documents Adding / Removing With Minimum Hits to the Database

I have a a model "Entry" that has many items "Items" that are embedded documents: class Entry embeds_many :items, cascade_callbacks: true ... end the issues is i have to move a bunch of embedded document Items around deleting some, add others,…
LMH
  • 949
  • 9
  • 22
2
votes
1 answer

Mongoid Undefined method [] for nil:nilClass

I have an application that queries an API and then attempts to store that query in the Mongo document. It seems pretty straightforward from the documentation, but I seem to be missing a step, but I have little idea of what's wrong. Could one of you…
BBB
  • 85
  • 1
  • 1
  • 8
2
votes
1 answer

saving and fetching hash in Mongoid Document

I am creating a metrics hash using the following: @metrics = Hash.new ... @metrics[:users][:year][:male] = ... @metrics[:users][:today][:male] = ... ... Metrics.new(:metrics => @metrics).save and I have the following class: class Metrics …
w2bro
  • 1,016
  • 1
  • 11
  • 36
2
votes
1 answer

Devise 2.1 are salts off by default?

devised moved the encryptable module to a different gem. However, they state that Bcrypt already uses a salt by default. I'm a bit confused. Without adding :encryptable to my models, are they salted?
CamelCamelCamel
  • 5,200
  • 8
  • 61
  • 93
2
votes
2 answers

Mongoid where greater than sum of two fields

Hi I'm using mongoid (mongodb) to go a greater than criteria: Account.where(:field1.gt => 10) But I was wondering if it was possible to do a criteria where the sum of two fields was greater than some number. Maybe something like this (but doesn't…
Brian Armstrong
  • 19,707
  • 17
  • 115
  • 144
2
votes
1 answer

Devise on STI with different authentication keys on different class

I have an STI model structure where super-class is User and sub-classes are Member and NonMember. I want to have only one Member and multiple NonMember for an email. For e.g. with email a@gmail.com there can be only one Member object but at the same…
abhas
  • 5,193
  • 1
  • 32
  • 56
2
votes
1 answer

Heroku not using the specified Ruby 1.9.3

Upgrading to Mongoid 3 and Ruby 1.9.3. Trying to use Ruby 1.9.3 on Heroku Cedar Stack. I have added the below to the top of my Gemfile: source 'http://rubygems.org' ruby "1.9.3" Pushing to Heroku, it seemed to be working -----> Heroku receiving…
Bashar Abdullah
  • 1,545
  • 1
  • 16
  • 27
2
votes
2 answers

can't convert Enumerator into Array

While working on one application I am getting this error: can't convert Enumerator into Array Here is my code, mr_collection is MongoID query. mr_collection = self.where(query).map_reduce(map, reduce).finalize(finalize).out({:replace =>…
Arpit Vaishnav
  • 4,739
  • 6
  • 39
  • 57
2
votes
1 answer

using elasticsearch to filter through tags with whitespace

I am using tire (https://github.com/karmi/tire) with mongoid. Here is my model definition: class SomethingWithTag include Mongoid::Document include Mongoid::Timestamps field :tags_array, type: Array include Tire::Model::Search include…
dementrock
  • 917
  • 3
  • 9
  • 21