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
1 answer

Mongoid: retrieving documents whose _id exists in another collection

I am trying to fetch the documents from a collection based on the existence of a reference to these documents in another collection. Let's say I have two collections Users and Courses and the models look like this: User: {_id, name} Course: {_id,…
balu
  • 23
  • 3
2
votes
1 answer

Mongoid fill out referenced ids

I'm building an autocomplete feature for my rails app. The input form makes an ajax call on keypress which then calls this search method in rails def search search = Regexp.new(params[:name]) @users = User.where(:name=>search) render…
K2xL
  • 9,730
  • 18
  • 64
  • 101
2
votes
1 answer

Mongoid Revert if fail

I have a validations in mongoid that I want to revert if it fails while saving the error message. Example if @thing.update_attributes(params[:thing]) format.html { redirect_to @thing, notice: 'Thing was successfully updated.' } format.json {…
GTDev
  • 5,488
  • 9
  • 49
  • 84
2
votes
1 answer

getting ActiveRecord errors when using mongoid and Sql on Ironworker files

(I am relatively new to Rails) I have a file (Ruby) I am running/uploading through Ironworker that is currently using MySql (activeRecord) for database. ALl works fine, but We now have a need for a new (additional) Model that will use Mongoid that…
jodu
  • 77
  • 8
2
votes
1 answer

Query with RegExp and Array

I have a class Post, with the following scope: scope :by_tag, ->(tag){ where(:desc => /##{Regexp.escape(tag)}/) } It works very well with one tags, but I can't make it work with various tags. For example: I cant make it give me the posts tagged…
caarlos0
  • 20,020
  • 27
  • 85
  • 160
2
votes
1 answer

MongoID: Group and Count

Supposing I have a model Post, wich contains only the field desc. The user can use hashtags, like #rails inside any posts... How can I list and count the hashtags used, for example, in the last 10 days? I'm do not know much about mongodb, but I see…
caarlos0
  • 20,020
  • 27
  • 85
  • 160
2
votes
1 answer

Map/Reduce Operation on Mongoid Criteria in version 2

am I correct in that MongoDB map/reduce feature is not available on Mongoid Criteria for MongoId version 2+ Can any one confirm this I have a criteria Here my Query class PerformerSource scope :active_performers,where(:active =>…
Ratatouille
  • 1,372
  • 5
  • 23
  • 50
2
votes
3 answers

Join two mongoid criteria

I have an array with two Mongoid::Criteria [#"1"}, options: {:sort=>[[:published_date, :desc]], :limit=>1}, class: News, embedded: false> , #
suvankar
  • 1,548
  • 1
  • 20
  • 28
2
votes
1 answer

mongoid-paperclip: Photo is not recognized by the 'identify' command

I'm migrating from Active Record to Mongoid, and this paperclip stuff used to work fine. I'm using Ubuntu 12.04. I've got this code in my mongoid document: has_mongoid_attached_file :photo, :styles => { :thumb => "60x60", :small =>…
2
votes
1 answer

Query document with embedded documents with date ranges in Mongoid

Suppose I have a user document who has many activities as an embedded document. Every time a user does something on the site an activity document is created (as an example). class User include Mongoid::Document has_many :activities end class…
Cimm
  • 4,653
  • 8
  • 40
  • 66
2
votes
1 answer

Replace embedded documents on save in Mongoid

I want to be able to replace the entire set of embedded documents in a MongoDB object on save - the HTML form will contain the entire new set. I also want it to validate everything before saving - i.e. don't trash the old documents, then validate…
p.g.l.hall
  • 1,961
  • 2
  • 15
  • 26
2
votes
1 answer

mongoid and validates_associated does not work

I'm using rails 3.2 and I building a nested form. But things are not working as I expect. First of all, my model is a Company with has many Addresses. Here is the model class Company include Mongoid::Document include Mongoid::Timestamps …
Müsli
  • 1,744
  • 7
  • 27
  • 50
2
votes
2 answers

Blog Gem/Engine for Rails/Mongoid

What Rails blogging gem/engines are there that can be used with MongoDB/Mongoid? I've used Typo and RefineryCMS-Blog for MySQL/ActiveRecord apps, but they don't work with Mongoid (and frankly are more heavyweight than I need).
Raphael
  • 1,701
  • 15
  • 26
2
votes
2 answers

How to perform this query on a hash in a MongoDB document (using Mongoid)

I am using Mongoid. I have a document that looks like the following: Pet: foo: {bar: 1, foobar: 2} another_attr: 1 In this case, preferably using Mongoid, how would I query for all pets that have a bar value greater than 0 where another_attr is…
randombits
  • 47,058
  • 76
  • 251
  • 433
2
votes
1 answer

Mongoid, belongs_to and embedded_in hot can id do?

I have three Models: User, Picture, and Like where: class Picture include Mongoid::Document embeds_many :likes belongs_to :user end class User include Mongoid::Document has_many :pictures has_many :likes end class Like …
matiasfha
  • 1,270
  • 4
  • 23
  • 42