mongoid

Will_paginate with mongoid (total_entries issue)

跟風遠走 提交于 2019-12-25 02:22:29
问题 When using mongoid with 'will_paginate' gem, it seems like method called 'total_entries' doesnt work which can affect perfomance 回答1: So I was using Mongoid with 'will_paginate' gem and I had this problem with 'total_entries' option, and to be more specific, I dont think it was working at all, which is not very good for perfomance in many situations... After a while I found this gem but it didnt look like 'total_entries' method was working there so here's what I did: 1) Opened mongoid

Using collection-level operations in Mongoid

徘徊边缘 提交于 2019-12-25 01:06:36
问题 I'm experimenting with Ruby (which I don't know very well) and Mongo (which I do.) I've made a Mongoid model with an :accessed field. I know that in Mongo I can just run something like: data = db.collection.findAndModify({ query: { ... }, update: {$inc: {accessed: 1}} }) But when I run MyModel.collection.find_and_modify in Mongoid, I get back what appears to be a hash. Is there a way I can coerce this into an instance of my model class, or do a better supported query in Mongoid? 回答1: By

IBMCloud - How can I connect to MongoDB?

≡放荡痞女 提交于 2019-12-24 22:33:35
问题 I'm trying to connect to MongoDB in a IBMCloud instance and I'm using MongoID. I ever use some configurations and try very things. I'm getting the error: MONGODB | Error running ismaster on address:port: system lib Here is my mongoid.yml that I'm trying to connect to mongoDB: development: clients: default: database: databasename hosts: - address:port - address:port options: user: 'admin' password: 'some-password' auth_mech: :scram auth_source: admin connect: :replica_set replica_set: replset

Query based on a child collection count with has_many association is showing always no results

南楼画角 提交于 2019-12-24 21:50:32
问题 I'm trying to base a query on the number of documents in the child collection. This is my context: class Pro include Mongoid::Document has_many :recommendations scope :lost, -> { where(:recommendation_ids => []) } scope :normal, -> { where(:recommendation_ids.ne => []) } end And the child collection: class Recommendation include Mongoid::Document belongs_to :pro end So, now I execute: >> Pro.lost.count 0 >> Pro.all.select{|p| p.recommendations.count == 0}.count 1 What am I doing wrong? I've

Mongoid find embedded document

夙愿已清 提交于 2019-12-24 16:35:41
问题 I'm trying to search for an embedded document by its id, and return it. This is possible, but only, as far as I see, by using mongo to find the document which embeds it, and then searching that document in ruby for the embedded document I'm after. Like this: # commenter.rb def post # todo: find syntax do avoid double query if user = User.any_of({'posts.commenter_ids' => self.id}).last user.posts.where('commenter_ids' => self.id).last end end Seems simple, but I haven't found anything I like

Efficient way to render ton of JSON on Heroku

ε祈祈猫儿з 提交于 2019-12-24 14:45:43
问题 I built a simple API with one endpoint. It scrapes files and currently has around 30,000 records. I would ideally like to be able to fetch all those records in JSON with one http call. Here is my Sinatra view code: require 'sinatra' require 'json' require 'mongoid' Mongoid.identity_map_enabled = false get '/' do content_type :json Book.all end I've tried the following: using multi_json with require './require.rb' require 'sinatra' require 'multi_json' MultiJson.engine = :yajl Mongoid.identity

how to ignore case-sensitiveness and include nested documents when searching on Rails 4 with Mongoid

别说谁变了你拦得住时间么 提交于 2019-12-24 13:25:36
问题 parent.rb class Parent include Mongoid::Document field :name, type: String field :hobby, type: String field :born, type: Date has_many :children accepts_nested_attributes_for :children def self.search(search) if search any_of({name: search}, {hobby: search}) end end end child.rb: class Child include Mongoid::Document field :name, type: String field :hobby, type: String field :born, type: Date belongs_to :parent end parents_controller.rb class ParentsController < ApplicationController before

Why am I getting error 500 “We're sorry but something went wrong” when pushing my app to Heroku?

淺唱寂寞╮ 提交于 2019-12-24 12:36:19
问题 I pushed my app to Heroku and am getting "We're sorry, but something went wrong (500)" Why is this? I know the error message is coming from one of my own files in the /public directory titled 500.html but i'm not sure why this is happening. My heroku logs are below as well as my mongoid.yml file. Thanks. Heroku logs: 2014-02-23T02:12:14.311710+00:00 heroku[router]: at=info method=GET path=/ host=danacamilleapp.herokuapp.com request_id=25556ae0-c4ac-40f7-8008-bd8860b87039 fwd="72.89.235.136"

Extracting, modelling and changing data model, with mongoid/mongodb

心已入冬 提交于 2019-12-24 11:16:27
问题 I'm looking for a better way, if it's possible, for manipulating an existing mondodb datamodel using amazing mongoid ODM driver. Suppose you have an embedded one to many data model like the following : class User include Mongoid::Document field :nickname embeds_many :watchlists end class Watchlist include Mongoid::Document field :html_url field :description field :tags_array, type: Array embedded_in :user end Now, for all users you want to extract just a part of every watchlist , if and only

Ruby on Rails Mongoid and Webfaction: Not Authorized For Query (Error 16550)

两盒软妹~` 提交于 2019-12-24 02:56:16
问题 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 "userAdminAnyDatabase" permission and am using it with this rails mongoid config: production: sessions: default: database: <table> hosts: - localhost:<port> username: <user> password: <password> I have the server runing with --auth flags and I also tried the user with the mongodb cpmmand line and