Tagged Questions
0
votes
1answer
15 views
mongoid before_destroy callback on has_and_belongs_to_many association
I have a simple has_and_belongs_to_many relation set up in Mongoid like so:
class Post
...
has_and_belongs_to_many :authors
scope :live, lambda{ published.where(:published_at.lt => ...
0
votes
1answer
30 views
Write data to Mongodb
Currently we are using
@collection.update id, c_doc, upsert: true, safe: true
Does setting the safe flag to True confirms that the data is actually written to the slaves and then written or it just ...
0
votes
1answer
24 views
Undefined method on an instance variable that is very much defined? Rails
I'm getting this classic error:
ActionView::Template::Error (undefined method `count' for nil:NilClass):
34: </li>
35: <%end%>
36:
37: ...
0
votes
1answer
10 views
Show action caused Mongoid Criteria error
I am simply trying to access the show page through my index page of an event but I keep getting this mongoid error-
Mongoid::Errors::DocumentNotFound at ...
0
votes
1answer
17 views
Should a model that participates in an association specify id fields for each associated resource?
For example, if we consider two models, Product and Brand, should I declare a field for each associated document's id in each model?
class Product
include Mongoid::Document
field :name, :type ...
1
vote
1answer
43 views
Stripe payments, adding price from another model into payment method
I have added Stripe payment to my app to handle registration payments for events, the form is on the event show page so the method is in the events controller but I have created a registration model. ...
0
votes
1answer
40 views
How does mongoid generate BSON ObjectId
This is with reference to this answer: http://stackoverflow.com/a/5694803/762747
So the BSON Object ID consists of:
[4 bytes seconds since epoch, 3 bytes machine hash, 2 bytes process ID, 3 bytes ...
0
votes
1answer
11 views
I am getting Mongoid::Errors::NoSessionsConfig: error when I run rspec
I am using Mongoid 4.0 with mongoDB v2.4.5 inside of a rails 4.0 and ruby 2.0 environment on Mountain Lion. When I run my rspec tests:
require 'spec_helper'
# This is a sample spec file, showing an ...
0
votes
1answer
35 views
Can't make mongo work with rails on Windows
I'm trying to test mongoDB with rails, I'm pretty new with both.
Firstly, mongoDB is installed and working as a Windows Service.
Now, this is the step I did to create a simple app:
I created the ...
-1
votes
1answer
24 views
Why don't new mongoid fields show up when adding them to model?
I added new fields to a model.
Then i do rake db:drop
I inspect the database and only the old fields are there. Why are the new fields not added?
0
votes
1answer
33 views
Foreign Keys and Mongoid
Are foreign keys explicitly required in relationships between two models in Mongoid? For example.
class User
include Mongoid::Document
has_many :posts
end
class Post
include Mongoid::Document
...
0
votes
1answer
25 views
Upload files with carrierwave
I'm trying to upload a file using Rails, Mongoid and Carrierwave. When I click submit, the value of "image" in the POST request is {url : null}. When I use logger to view the value of "image" from the ...
1
vote
1answer
29 views
Heroku Asks for PG gem when I have Mongoid
I'm receiving the following error
Please install the postgresql adapter: `gem install activerecord-postgresql-adapter` (pg is not part of the bundle. Add it to Gemfile.) (LoadError)
whenever I ...
0
votes
2answers
23 views
Rails functional tests fail for MongoDB with ActiveRecord/SQLite3 error
I'm using Mongoid with Rails but all of the functional tests that have been generated are failing with an error similar to:
test_should_get_new(PostsControllerTest):
ActiveRecord::StatementInvalid: ...
0
votes
1answer
20 views
Patching Module in Ruby
I'm trying to add the following code that I found online as a workaround for a problem with combining MongoDB and Backbone.js in Rails, but I actually don't know Ruby/Rails that well because I'm ...
0
votes
0answers
43 views
Ruby on Rails Mongoid and Webfaction: Not Authorized For Query (Error 16550)
I am using version 2.4.4, followed the procedures at http://docs.webfaction.com/software/mongodb.html and am using Mongoid with Ruby on Rails. I also have created a user at the db I am using with the ...
1
vote
1answer
29 views
Connecting to mongodb on different server from rails console
I have deployed my rails application on ec2 instance, database used is Mongo and hosted on a separate instance.
The database and hosts in mongoid.yml have been changed accordingly which points to the ...
1
vote
1answer
41 views
Getting “Moped::Errors::ConnectionFailure:” error while trying to run rspec tests
I am getting the following error for the all rspec tests, which have been working fine before... Really strange thing is that I didn't change anything with regard to mongod or rspec or mongoid... :( ...
2
votes
0answers
26 views
How to “CAST” a Time field as Date in Mongoid
I am using Mongoid as my Rails app's ORM and have a problem with one grouping issue.
The collection/model is basically a transaction log with timestamps and I would like to do some grouping based on ...
1
vote
1answer
28 views
Parent fields are all nil when accessed by child (embedded 1-n)
I have a 1-n relationship defined as follows:
class User
field :email, type: String
embeds_many :papers
end
class Paper
embedded_in :user
end
If I try and access the parent fields (user) ...
2
votes
2answers
46 views
Exclude fields from document in mongoid?
I have a Record model with many dynamic attributes. I want to make a request to the model an send the response as JSON to the client. But i want to exclude fields like _id and all foreign_keys in this ...
0
votes
1answer
35 views
Connection settings for development server for mongo on rails
If my production (heroku) connection settings in mongoid.yml are:
sessions:
default:
uri: <%= ENV['MONGOHQ_URL'] %>
options:
skip_version_check: true
safe: true
...
4
votes
2answers
133 views
Rails with different two Databases
I have used two different databases for my rails application: MongoDB and MsSQL using mongoid and activerecord-sqlserver-adapter adaptor respectively. Everything is well but there is a problem while ...
1
vote
1answer
24 views
Retrieve existing MongoDB collection after adding inheritance
I'm using Mongoid as my DB wrapper. I had a model with no inheritance and thousands of documents in the collection. I then refactored it to inherit from a base class. Now I can't retrieve the original ...
0
votes
1answer
55 views
Rails 3: converting large arrays to JSON takes nearly 5 seconds?
assuming we're interpreting this new relic trace correctly, it seems that 4.75s is spent converting large arrays to JSON strings. is this possible? we're not using ruby enterprise edition but ruby ...
1
vote
1answer
35 views
Rails Mongoid select where key/value pair in array
so I have a collection Groups that looks like this
[
{
\"_id\": \"51bdff3968c7c4dd30000003\",
\"members\": [
{
\"id\": \"51bdedef68c7c4bc7c000001\",
...
2
votes
0answers
47 views
Uninitialized constant in Ruby on Rails demo app
I'm new in RoR, so,i'm following a demo app with the addition that i'm using mongo, after create the new project, that just modeles an user with name and email, like this:
rails generate scaffold ...
3
votes
1answer
163 views
Mongoid w/ Rails, attr_accessible --> “No method found”
Generated Rails App w/out Active Record
Added appropriate gems for Mongoid (Mongodb & Mongoid)
Generated the mongoid.yml file in config/ with rails support
Created a friend model and user ...
0
votes
2answers
34 views
Rails - Where MongoDB (Mongoid) stores db and logs?
I am new to MongoDB and Mongoid and I am using Debian testing(jessie/sid).
When I open /etc/mongodb.conf there is no information about where Mongoid stores db and logs.
It just mentions ...
0
votes
1answer
33 views
Mongoid: Sorting by two dates
This might be an odd one, but I've got documents with two dates. created_at and featured_at.
I want to sort by featured_at first, then created_at. Though when I do something as simple as ...
0
votes
1answer
18 views
mongo + passenger: right way to reconnect to database from within rails? how to ensure optimal mongo performance?
we're on rails 3.2.12, passenger + nginx (1.0.10), mongo 2.2, and mongomapper 0.12.
we were told that passenger and mongo don't work well together unless there is a configuration set to ensure speedy ...
0
votes
2answers
51 views
Rails CSV import not functioning properly
Basically, CSV import doesn't work.
Model Code:
def self.import(file,admin_id)
spreadsheet = open_spreadsheet(file)
header = spreadsheet.row(1)
(2..spreadsheet.last_row).each do |i|
row = ...
0
votes
1answer
52 views
recommended pool size to set for mongo from a rails app (nginx, mongomapper)?
our app runs on rails 3.2.12, mongo 2.2 (will migrate to 2.4), mongomapper, and uses nginx + passenger.
if we're on a VPS with 5 GB of RAM, what's the best way to determine the optimal pool size for ...
0
votes
0answers
25 views
Best way to implement subset of relation in rails with mongoid?
I have three models in a rails application:
Class Member
include Mongoid::Document
has_and_belongs_to_many :organizations, inverse_of: :members
has_and_belongs_to_many :orgadmin, inverse_of: ...
0
votes
0answers
34 views
How override a setter and getter method for an Mongoid attribute?
I have some attributes with too reads and writes in Mongo DB, I thought to store on Redis only this attributes for reduce load on server.
Now I need to override the setter and getter methods on ...
0
votes
1answer
33 views
Pretty BSON::OrderedHash using Rails
If I pass a BSON::OrderedHash (from a MongoDb collection) to JSON.pretty_generate I get the json document but unformatted. How can I get a bson document formatted like .pretty() does?
0
votes
1answer
23 views
How to access MongoDB in rails without using Mongo as the app's DB
I want to be able to access data from a mongoDB while still use my sqlite3 as the db for my app. For example, my controller for my db_call model is the following:
require 'rubygems'
require 'mongo'
...
1
vote
1answer
51 views
Model attribute contains collection of object
I have main model Page, which is container.
The page can have some to-do lists, notes, files and discussions. The idea is to have them in special order.
Page.last.container # [Todolist_obj, ...
3
votes
1answer
117 views
Rails 3 Calculate age of embedded records
I'm using mongodb, and have a model that adds comments as embedded documents.
How do I get the average age of comments for an entry? (relative example, my fields vary a little)
So I can have many ...
0
votes
1answer
54 views
how to select children documents in mongoid
The specific problem
I have three classes set up in a tree
Group Owner class:
class GroupOwner
include Mongoid::Document
field :origin_id, type: BSON::ObjectId
field :origin_type, type: ...
0
votes
0answers
21 views
Fragment cache strategy advice: list of categories and top posts for each of them
I'm new to caching, I've read a lot and particularly liked this post of 37Signals.
On many page of my site I'm struggling to optimize a situation like this:
Q: How can I fragment cache these ...
0
votes
1answer
64 views
How to persist a MongoDB cursor in between requests?
In the contest of a web server:
In order to avoid re-querying (using find), one could try and keep between requests the cursor reference returned by find. The Cursor object is a complex object ...
0
votes
1answer
29 views
Rails app with Mongoid not saving on update
I'm making a Rails app that uses Mongoid and devise. Currently, the functionality's pretty basic, but it's not working like I expect it to. In particular, update isn't working at all.
I can create a ...
0
votes
1answer
28 views
Paginate is limiting my csv export using Comma gem - how to work around?
Here is the relevant code:
def index
@customer = Customer.new
if(session[:admin_id])
@allJobs = Job.where(:merchant_id => session[:admin_id].to_s).paginate(:per_page => 15, :page ...
1
vote
2answers
51 views
How do I switch the database used in a Rails application?
I have an application based on the Devise cancan repo. Currently it is using SQLite3 as its database.
I was wondering how someone would change the system to something like MongoDB or a SQL database?
...
3
votes
1answer
28 views
How to use existing mongodb collection in rails3.2
I have a collection in a mongodb imported from csv file, and I want to load that into my ruby-on-rails3.2.13 app to list the collections document in homepage.
I have used mongoid as an object document ...
0
votes
0answers
39 views
Cannot use datetime_select with Mongoid
Every time I try to use Datetime_select in a view, the app throws an attribute error.
Mongoid::Errors::UnknownAttribute:
Problem:
Attempted to set a value for 'fromtime(1i)' which is not ...
0
votes
1answer
53 views
Mongoid - has_many: parent losing relation to child
I have the following (simplified) relation:
class Project
include Mongoid::Document
field :name
field :description
has_many :payments
end
class Payment
include Mongoid::Document
field ...
0
votes
2answers
53 views
inserting array data in mongodb using rails
I am not able to insert data in mongodb using rails if the data type is of array type
following is the code
def friend
Twitter.configure do |config|
config.consumer_key = 'GpCZ3ppx2tvOYB7mP4FONw'
...
0
votes
0answers
50 views
Map Reduce with Mongoid
I have ContentType and Content models, such that; Content belongs to ContentType.
Now I need Content collection of type Mongoid::Criteria (similar to Content.all and as opposed to Array), but with ...