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
97
votes
4 answers

How to implement has_many :through relationships with Mongoid and mongodb?

Using this modified example from the Rails guides, how does one model a relational "has_many :through" association using mongoid? The challenge is that mongoid does not support has_many :through as ActiveRecord does. # doctor checking out…
Mario Zigliotto
  • 8,315
  • 7
  • 52
  • 71
87
votes
3 answers

Select where not null or empty in mongoid

I modified a model so it includes a new field, such as... field :url, :type => String I use activeadmin, so when I create a new entry @model.url is empty, and in entries created before changing the schema it's nil. How do I select both? I have…
methodofaction
  • 70,885
  • 21
  • 151
  • 164
83
votes
14 answers

Mongoid or MongoMapper?

I have tried MongoMapper and it is feature complete (offering almost all AR functionality) but i was not very happy with the performance when using large datasets. Has anyone compared with Mongoid? Any performance gains ?
PanosJee
  • 3,866
  • 6
  • 36
  • 49
82
votes
4 answers

Difference between "id" and "_id" fields in MongoDB

Is there any difference between using the field ID or _ID from a MongoDB document? I am asking this, because I usually use "_id", however I saw this sort({id:-1}) in the documentation:…
Arthur Neves
  • 11,840
  • 8
  • 60
  • 73
71
votes
2 answers

Using Active Record generators after Mongoid installation?

I'm using MongoDB via Mongoid integration, as well as ActiveRecord in a project. I would like to generate migrations for active record, and Mongoid is the default when I run. rails g migration Any ideas how to specify AR as my default generator…
Allyl Isocyanate
  • 13,306
  • 17
  • 79
  • 130
63
votes
3 answers

MongoDB: count the number of items in an array

I have a collection where every document in the collection has an array named foo that contains a set of embedded documents. Is there currently a trivial way in the MongoDB shell to count how many instances are within foo? something…
randombits
  • 47,058
  • 76
  • 251
  • 433
47
votes
3 answers

How can I disable MongoDB log messages in console?

I have this little test script: require 'mongo' mongo_client = Mongo::Client.new(['127.0.0.1:27017'], :database => 'test') mongo_client[:collection].insert_one({a: 1}) An this is the console output: $ ruby test.rb D, [2015-05-17T21:12:05.504986…
raulmarcosl
  • 793
  • 1
  • 6
  • 10
46
votes
5 answers

Mongoid OR query syntax

This must be asked alot but it is very poorly documented. There is no mention at http://mongoid.org/en/mongoid/docs/querying.html I'm trying to check whether a user exists (below is an AND query), how can I change it to an OR type…
Tarang
  • 75,157
  • 39
  • 215
  • 276
42
votes
6 answers

Finding mongoDB records in batches (using mongoid ruby adapter)

Using rails 3 and mongoDB with the mongoid adapter, how can I batch finds to the mongo DB? I need to grab all the records in a particular mongo DB collection and index them in solr (initial index of data for searching). The problem I'm having is…
Dan L
  • 4,319
  • 5
  • 41
  • 74
41
votes
4 answers

Batch insert/update using Mongoid?

I googled and all others, but I didn't find the answer. The question is: Hi, how can I do batch insert with Mongoid to MongoDB?
millisami
  • 9,931
  • 15
  • 70
  • 112
41
votes
7 answers

ERROR Original Error: ImageMagick/GraphicsMagick is not installed

I have an app that is using Imagemagick, but I had to rebuild my environment and now when I try and upload an avatar (which is why I am using Imagemagick), it keeps giving me the following error when I try to add an image. Avatar Failed to…
SupremeA
  • 1,519
  • 3
  • 26
  • 43
41
votes
3 answers

How can I see raw mongoDB queries with Mongoid

I followed this page to see mongoDB queries. As a result I could see Moped log. But I can't see raw mongoDB queries. How can I display MongoDB queries in the rails console/server I did like the below. # in [rails…
Teruki Shinohara
  • 783
  • 1
  • 9
  • 12
41
votes
1 answer

Difference between embeds_many and has_many in mongoid

Can anyone explain to me the difference between embeds_many and has_many in mongoid?
enRai
  • 671
  • 6
  • 12
40
votes
5 answers

Mongoid Rails 4 sort by asc or desc order created_at

I have a rails 4 app using Mongoid. I want to do something basic is display the book model I have by descending order according to the field created_at in the index view. In the controller books_controller.rb: def index @books =…
Chleo
  • 935
  • 2
  • 8
  • 14
37
votes
2 answers

Factory Girl + Mongoid embedded documents in fixtures

Let’s say you have the following mongoid documents: class User include Mongoid::Document embeds_one :name end class UserName include Mongoid::Document field :first field :last_initial embedded_in :user end How do you…
GTDev
  • 5,488
  • 9
  • 49
  • 84
1
2 3
99 100