Mongoid Document Not Found Error
Contents |
Sign in Pricing Blog Support Search GitHub This repository Watch 391 Star 8,316 Fork 1,564 sinatra/sinatra Code Issues 35 Pull requests 15 Projects 0 Pulse Graphs New mongoid raise_not_found_error issue error Mongoid::Errors::DocumentNotFound does not pass #1005 Closed adrianotadao opened this Issue
Rescue Mongoid::errors::documentnotfound
May 6, 2015 · 13 comments Projects None yet Labels debug feedback Milestone No milestone Assignees
Mongoid Not Found Exception
No one assigned 5 participants adrianotadao commented May 6, 2015 Hi all, I'm trying to handle error with sinatra but does not works to me. Look at this: Works get '/'
Mongoid Find Without Exception
do begin Namespace.find(params[:id]) rescue Mongoid::Errors::DocumentNotFound #Here works end end Does not works error Mongoid::Errors::DocumentNotFound do #Does not pass here end I'm using: gem 'sinatra', '1.4.6' gem 'mongoid', '4.0.2' Any idea? Sinatra member kytrinyx commented May 7, 2015 Do you have the same issue if you create your own error type? e.g. class FancyError < StandardError end error FancyError do # does this work? mongoid find_by end adrianotadao commented May 8, 2015 Hi @kytrinyx, That way, works. But it would be much better if it works as: error Mongoid::Errors::DocumentNotFound do end Sinatra member kytrinyx commented May 8, 2015 Yes, I wasn't suggesting that you should wrap the mongoid error, I'm trying to figure out how to reproduce this with the smallest amount of code. Would you be able to write a small one-file app that shows the problem, and link to it as a gist? adrianotadao commented May 12, 2015 @kytrinyx thank you for your time ... I made an example with sinatra and mongoid. Could you take a look? Thanks a lot. adrianotadao commented May 26, 2015 @kytrinyx Hello... If you think that is a bug, I can try to fix this. 👍 Sinatra member kytrinyx commented May 29, 2015 Sorry -- I've got this on my list to look at, but I just moved house so the past 2 weeks have been really chaotic. I'm planning on catching up with everything this weekend. Sinatra member kgrz commented Jun 7, 2015 @adrianotadao Hello, I've tried to get a sample script working: https://gist.github.com/kgr
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss mongoid config the workings and policies of this site About Us Learn more about mongoid 5 Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each https://github.com/sinatra/sinatra/issues/1005 other. Join them; it only takes a minute: Sign up Mongoid/Rails 4 Documents not found error up vote 1 down vote favorite Im trying to use the alternative of "foreign keys", embedded_in and embeds_many in rails 4. I'm sure there is a way round this and its making sense to me so far My Models: class Line include http://stackoverflow.com/questions/35997307/mongoid-rails-4-documents-not-found-error Mongoid::Document include Mongoid::Timestamps embeds_many :stations field :line, type: String index({ starred: 1 }) end class Station include Mongoid::Document include Mongoid::Timestamps has_many :routes embedded_in :line, inverse_of: :stations field :name, type: String end Now I'm able to create a nested route such as: http://localhost:3000/lines/:line_id/stations with: Rails.application.routes.draw do resources :lines do resources :stations end resources :routes root 'lines#index' end My Stations Controller: class StationsController < ApplicationController before_action :load_line before_action :set_station, only: [:show, :edit, :update, :destroy] # GET /stations # GET /stations.json def index @stations = @line.stations end # GET /stations/1 # GET /stations/1.json def show end # GET /stations/new def new @station = @line.stations.build end # GET /stations/1/edit def edit end # POST /stations # POST /stations.json def create @station = @line.stations.build(station_params) respond_to do |format| if @station.save format.html { redirect_to @station, notice: 'Station was successfully created.' } format.json { render :show, status: :created, location: @station } else format.html { render :new } format.json { render json: @station.errors, status: :unprocessable_entity } end end end # PATCH/PUT /stations/1 # PATCH/PUT /stations/1.json def update respond_to do |format| if @station.update_attribut
here for a quick overview of the site Help Center Detailed answers to any http://stackoverflow.com/questions/30416579/raise-not-found-error-configuration-to-false-not-working questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack not found Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up raise_not_found_error configuration to false not working up vote 0 down vote favorite I am playing around with rails and mongodb and running into the issue where find_by returns an mongoid document not error when it does not find a result. I have already triple checked to make sure it's under options and not session/options. Can anyone help? thanks already checked to make sure it's set under options, not session options Error Mongoid::Errors::DocumentNotFound: Problem: Document not found for class VinDecode with attributes {:numOfDoors=>"3"}. Summary: When calling VinDecode.find_by with a hash of attributes, all attributes provided must match a document in the database or this error will be raised. Resolution: Search for attributes that are in the database or set the Mongoid.raise_not_found_error configuration option to false, which will cause a nil to be returned instead of raising this error. Below is my mongoid.yml development: sessions: default: database: myapp_development hosts: - localhost:27017 options: options: raise_not_found_error: false test: sessions: default: database: myapp_test hosts: - localhost:27017 options: read: primary # In the test environment we lower the retries and retry interval to # low amounts for fast failures. max_retries: 1 retry_interv