Questions tagged [mongoid]

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

mongoid
Filter by
Sorted by
Tagged with
1 vote
1 answer
43 views

How can I force the correct hash access syntax from my text_field form helper?

I am working on a Rails project, using Mongo. I am faced with an issue in my view form helper, in that (whether this access is through Rails or Mongoid, I am not sure) I am attempting to access a ...
4 votes
1 answer
111 views

Mongoid: Get users that are missing documents of at least one category

I'm using Ruby On Rails with Mongoid for the ORM. I have a User class and a Document class. User has_many documents. A Document has a category. There are multiple categories, but some of them are ...
1 vote
1 answer
785 views

Mongoid 3 callbacks: before_upsert vs. before_save

For Mongoid 3+, is there a diagram/description of the various callbacks? http://mongoid.org/en/mongoid/v3/callbacks.html For example, what's the difference between before_upsert vs. before_save. Isn't ...
1 vote
0 answers
36 views

When multiple conditions are using index condition, combine them(using or operator) together, would it still be performant?

We have a system, which are using rails and mongoid, in the system post can have comments, and comments can have any nested level, so I use nested set to implement it, then post's top level comments ...
1 vote
2 answers
238 views

Mongo $lookup Query Getting as alias blank

db.ticket.aggregate([ { $lookup: { from: "crmorder", localField: "subOrderId", foreignField: "currentStatus", as: "comments" } } ]) in the result comments field is ...
-2 votes
2 answers
126 views

string handling in Ruby on Rails bring difficulties

I am using Cancan In my user model there is ROLES = %w[admin user ram] I want to bring the value from my own module . all= Role.all @all.each do |all| all.name end Here i can carry all value ...
1 vote
2 answers
386 views

How to change model owner in Ruby on Rails?

I use Ruby on rails and mongoid. I have two models User.rb and Project.rb. If I want to change owner of Project model, how should I do this? User.rb class User include Mongoid::Document field :...
1 vote
3 answers
8k views

Mongo::Error::NoServerAvailable: No primary server is available in cluster

I am getting the following error when deploying to production environment (via gitlab): Mongo::Error::NoServerAvailable: No primary server is available in cluster: #<Cluster topology= ...
1 vote
0 answers
12 views

Avoid auto persist when deleting document from embedded association

MongoID currently auto persist the parent document along with the embedded association when removing anything from the embed-many association. Is there a way to avoid this auto persist? Document model ...
47 votes
3 answers
21k views

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 ...
0 votes
0 answers
2k views

BSONError: Invalid UTF-8 string in BSON document (mongodb)

I have a database which using mongo v3.4.3. I created a dump using mongodump command and restored using mongorestoreto the same version of database. I got an error Cannot create index in mongodb, key ...
1 vote
0 answers
58 views

How to update embedded object of an array inside mongodb document using mongoid with ruby?

I want to update an embedded object of an array inside of mongodb collection using ruby and mongoid. I have an schema like this { _id: 23234342, age: 23, customer_name: 'alex', email: 'alex@...
1 vote
1 answer
164 views

Using Atlas Search with Mongoid on Rails

I am trying to get full text search with Atlas to work in my Rails app. I have set up the index following this tutorial in their docs. When I test the query in a vacuum it seems to work as expected, I'...
2 votes
1 answer
74 views

Could not find generator 'mongoid:config'. When rails generate mongoid:config

I'm new to Ruby on Rails.I've been trying generate mongoid.yml file to connect with mongodb. but im getting this error: `Could not find generator 'mongoid:config'. Did you mean? mongoid:devise Run `...
2 votes
3 answers
4k views

OR query matching nil or "" with Mongoid still matches ""?

I'm trying to write a query for an embedded Mongoid::Document which finds any record where the "address" field is neither nil nor "". Using a combination of the MongoDB documentation, this issue in ...
13 votes
5 answers
7k views

Case insensitive searching for words in mongoid

Is there a way to set an attribute in mongoid for case insensitive searches? Lets say that somebody has a username: IAmGreat and I want to find the users data using their unique username without ...
3 votes
1 answer
232 views

Ruby `debug` gem does not accept arrow keys and shows the key typing as ASCII sequences, and then frozes

I am currently using Ruby on Rails 7, PostgreSQL, MongoDB and GraphQL to develop a web application. However, when I was trying to debug the Ruby code, rgdb does not take arrow keys correctly, and then ...
1 vote
2 answers
2k views

Perform Atomic Block Transactions in Rails with Mongoid

I'm using Rails 4.1.4 and Mongoid in my app. I just wanted to know if there's a way to perform a block transaction atomically using Mongoid in Rails. To make things clear, suppose I have this: ...
1 vote
0 answers
279 views

Connecting to AWS Document DB (MongoDB) with rails mongoid

I am trying to connect to AWS Document DB (MongoDB) in rails using "mongoid" gem (7.5.1) which internally uses mongo gem (2.18) dev: clients: default: database: my_database_name ...
13 votes
4 answers
9k views

mongoid .limit does not work in mongoid 3.1.x

i tried something like this in rails with mongoid 3.1.0 and lastest 3.1.3. .limit does not work. below it should return 1 row but it returns all (4) code: @go = Gallery.limit(1) logger.info "count: #...
1 vote
2 answers
5k views

How to use bsondump in windows

How to use bsondump and its command in windows. when i am running bsondump foo.bson > foo.json error: 'bsondump' is not recognized as an internal or external command, operable program or batch file. ...
1 vote
1 answer
88 views

Is it possible to use Rails action_text with mongoid?

I am starting an blog with mongoid and I would like to use trix editor along with all facilities of action_text. Is it possible?
1 vote
1 answer
346 views

Mongo::Error::OperationFailure: BSON field 'delete.deletes.q' is missing but a required field

I'm upgrading a rails app thats using MongoDB starting at Rails 4.2 and MongoDB 3.4 Ruby version is 2.7.6 MongoDB is 3.7 Rails 5.2 I've updated the app from database_cleaner to database_cleaner-...
1 vote
1 answer
30 views

how to use Mongoid to query by a column with the name 'id'

I have a collection with a column named id. When I tried to do a where query to filter by that column name, it returns no match because mongoid is aliasing id to the internal _id field instead. Is ...
1 vote
0 answers
132 views

Getting Error while running rails server - undefined method `blank_criteria' for class `Array' (NameError) from mongoid.rb file

Rails version 5.2.2 Ruby version 2.6.1 Mongoid version 8.0.2 I am using docker and there also I am getting same issue. Tried locally as well with rails s and getting same issue there. Its not allowing ...
1 vote
1 answer
42 views

Mongoid equivalent of ActiveRecord's "collection?" method for relations

I am using Mongoid and trying to do something similar to ActiveRecord's collection? method. I have a method that gets the relations from a class like: def relations object.class.relations end This ...
0 votes
3 answers
147 views

mongoid equivalent of loaded?

In a Rails app, using ActiveRecord with mysql, you can check to see if an association has been loaded: class A belongs_to :b a = A.find(... a.b.loaded? # returns whether the associated object ...
1 vote
2 answers
1k views

How to nested eager loading in mongoid?

Class Band include Mongoid::Document has_many :albums end Class Album include Mongoid::Document has_many :musics belongs_to :band end Class Music include Mongoid::Document belongs_to :...
1 vote
2 answers
5k views

Mongo::Error::OperationFailure Unknown modifier: $pushAll when updating a model (mongoid, angular, rails)

I am using angular-8 on the front-end and Rails(5.2) on backend with Mongoid(6.1). I have a multi-level nested form for model Event that accepts_nested_attributes_for Ticket that in turn ...
2 votes
1 answer
413 views

Convert mongoid aggregated result to ruby object

I am querying a Model in Rails using mongoid product1 = Products.where(list_id: params[:list_id]) @records = product1.collection.aggregate([ { "$match": { "rowdatas.field_value": {...
0 votes
1 answer
217 views

undefined method `eager_load' for Book:Class (NoMethodError)

I getting an error using rails 6 ( Ruby 3.1.2) with mongoid. without the eager_load this will causes me a huge timeout and it affect the loading time and some times it gives a 500 status. but it's not ...
0 votes
1 answer
454 views

Omniauth session lost during authentication

I'm working on an application which uses Discord OAuth as a authentication method. Because this app needs a Discord account to have, I just use omniauth-discord, and not any local authentication ...
5 votes
4 answers
2k views

How to use AWS Document DB with Ruby On Rails? Compatibility with version 3.6?

recently AWS implemented compatibility with MongoDB version 3.6 via DocumentDB. Document DB requires a certificate that can be downloaded at: https://s3-us-gov-west-1.amazonaws.com/rds-downloads/rds-...
3 votes
3 answers
2k views

Mongoid and counter_cache column

I have Comment model: class Comment include Mongoid::Document include Mongoid::Timestamps belongs_to :commentable, polymorphic: true, touch: true#, counter_cache: true When I run: Article....
0 votes
3 answers
363 views

Mongoid Dynamic store_in

I have this XslSheet model which I would like to change the collection it's saved in based on the name of another model. I have tried to create a method inside my XslSheet model like so: def ...
0 votes
2 answers
246 views

Has mongoid replacement for rails save(touch: false)

Ruby on Rails active_record has option {touch: false}, when record is saved to database, since version 5. https://blog.bigbinary.com/2016/05/09/rails-5-allows-updating-without-updating-timestamps.html ...
0 votes
1 answer
72 views

How to rereduce with Mongoid to aggrerate data from two distinct fields?

The context Two documents of a mongodb mapped on rails/mongoid classes. The two class are Task and Subscription. For performance reasons, Subscription.current_task stores a Task::CurrentTask which is ...
0 votes
1 answer
58 views

How to execute runCommand with Mongoid > v7?

How to run db.runCommand in newer versions of mongoid. Example: MyModel.collection.database.command(eval: "db.runCommand ( { compact: 'sessions' } )" ) used to work in older version of ...
0 votes
2 answers
2k views

ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base with mongoid

I have a Rails 4.2.8 app, ruby 2.4.4 with a Mongo database, using the mongoid ODB. I want to run tests against this application using rspec. The most basic test gives me this error: ActiveRecord::...
1 vote
3 answers
3k views

Rails form to edit JSON object as text

I'd like to make a form that lets a user edit one field of a mongoid object as rendered JSON text. There's a field in the model that my rails app should not understand, but I want to expose a generic ...
3 votes
1 answer
732 views

Mongoid::Criteria can't modify frozen String

This perplexes me. A Mongoid::Criteria is not frozen, but if I assign it to a variable in console, it tells me FrozenError (can't modify frozen String: "#<Mongoid::Criteria Why would that be, ...
8 votes
2 answers
6k views

Upsert in Mongoid

Is there a built-in way to make upsert (insert if not exists) in Mongoid? Or should I check if an item exists first and only after that make insert/update?
0 votes
1 answer
108 views

Rails/Mongoid: How to change a mongoid model name? Data should not loose

I have a mongoid model in my rails application as follows class Groups::Post include Mongoid::Document include Mongoid::Attributes::Dynamic include Mongoid::Timestamps end I wanted to change ...
1 vote
1 answer
62 views

How rails ActiveRecord or Nosql ORM like mongoid handle has_many, has_one side of the relationship?

Lets Say I have User and a Team model. class User #some fields has_one :team end class Team #some fields belongs_to :user end Now when i do User.last.update(...
0 votes
1 answer
42 views

Mongoid Rails 5 convert string with multiple arguments to symbolized value for order_by method

I have a controller method where I'm trying to pass a string with multiple order_by arguments to return a sorted collection. The order_by syntax works with one stringified argument, i.e. order_param = ...
0 votes
1 answer
171 views

Mongoid skip validation or set default value for document with nil embeds_many

Mongoid won't save document with no reference to embeds_many field, and I can't find any mention in documentation on how to make embeds_many default to [] if not present, or alternatively to skip that ...
0 votes
1 answer
901 views

How to fix: Mongo::Error::OperationFailure

The production log on my Ruby on Rails app, has some of the following error types: Mongo::Error::OperationFailure [225:TransactionTooOld]: Retryable write with txnNumber 12 is prohibited on ...
12 votes
4 answers
4k views

MongoDB Aggregation: Compute Running Totals from sum of previous rows

Sample Documents: { time: ISODate("2013-10-10T20:55:36Z"), value: 1 } { time: ISODate("2013-10-10T22:43:16Z"), value: 2 } { time: ISODate("2013-10-11T19:12:66Z"), value: ...
1 vote
2 answers
2k views

Is there a way to seed hashes using the Faker gem?

I am trying to seed some data but I have a field that takes in a hash. When I do the following 50.times do Event.create( name: Faker::Internet.name, data: Faker::Lorem.words(4), uri: ...
1 vote
1 answer
172 views

NameError: uninitialized constant Mongoid::Relations after upgrading to mongoid 7.0

I am in the process of upgrading from rails 5.2 to 6.0. In that process, I also had to upgrade mongoid 6.0 to 7.0 Right after that, my rake scripts fail with this: rake aborted! NameError: ...

1
2
3 4 5
95