mongoid

insert new inner object into existing object mongodb using php

南笙酒味 提交于 2019-12-11 16:07:49
问题 I have the following document in my mongo collection {"_id":"5a9e97557cf28c1c2d00003d", "user_id":"avi12", "name":"Avinash", "Friends":{ "avi12":{ "From":"avi12", "To":"chandu", "Friend_status":"pending", "Time":1520342869, "requestid":"s_avi12_first" }, "second_user":{ "From":"avi122", "To":"chandu2", "Friend_status":"pending2", "Time":1520342869, "requestid":"2s_avi12_first" } } } I want to inset new object ("Third user") into Friends object . I have tried the following code... $update

I am trying to querymongodb collection to get one particular id field -

笑着哭i 提交于 2019-12-11 14:49:24
问题 I am trying to get _id from last updated("timeSliceStart") row which has matching "EmployeeName" DBCursor cursor = collection.find(EmployeeName).sort(new BasicDBObject("timeSliceStart", -1)).limit(1); while(cursor.hasNext()) { String result = cursor.next().get("id"); } Data in Mongo DB:: { "_id" : { "employeeId" : "1234567890", "@objectName" : "FeedMetadata" }, "school" : false, "college" : null, "errorCount" : 0, "errors" : [], "EmployeeName" : "Peter" } The result that is getting printed is

Odd results from mongoid using Debian squeeze mongodb

江枫思渺然 提交于 2019-12-11 14:23:05
问题 I'm experiencing odd results in data returned from gem, mongoid using mongodb on Debian squeeze. The data is good. How can I stop these consistent failures to return the data correctly? My mongodb is the latest in Debian squeeze backports and I'm using gem mongoid. $ dpkg-query -l mongodb mongodb 1:2.0.0-2~bpo60+1 I did $ sudo apt-get -t squeeze-backports install mongodb to get the newest version. 回答1: For anyone experiencing odd problems on Debian squeeze mongodb, it seems that currently the

RailsAdmin custom action to restore soft deleted records

牧云@^-^@ 提交于 2019-12-11 14:01:37
问题 I am using Rails 4.1.14 with rails_admin 0.8.1, mongoid 5.0 and mongoid_paranoia. I created RailsAdmin custom action to restore soft deleted Users. class Restore ... register_instance_option :controller do Proc.new do object.restore ... end end end But I keep getting User with id '5695997df5740c17b0000002' could not be found From my develoment.log Started GET "/admin/user/5695997df5740c17b0000002/restore" for 127.0.0.1 at 2016-01-12 16:35:04 -0800 Processing by RailsAdmin::MainController

Mongoid: disabling validation on inverse objects when saving parent for HABTM relationship Options

我的未来我决定 提交于 2019-12-11 11:40:58
问题 I have the following: def User has_and_belongs_to_many: :following, class: "User", inverse: :followers has_and_belongs_to_many: :followers, class: "User", inverse: :following end Note that User is also a Devise object. This means that when you save a User it requires :password and :password_confirmation to save. In the context of a rails app using Devise, and I have access to the current_user who is the currently signed in user: following_user = User.find(following_id) current_user.following

Sortable -table columns is not working in MongoDB

蹲街弑〆低调 提交于 2019-12-11 10:37:47
问题 I am using rails cast video http://railscasts.com/episodes/240-search-sort-paginate-with-ajax . It works fine for Mysql database. i want to implement this in Mongodb. my application_helper.rb file is like this def sortable(column, title = nil) title ||= column.titleize css_class = column == sort_column ? "current #{sort_direction}" : nil direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc" link_to title, params.merge(:sort => column, :direction => direction, :page =>

Mongoid aggregate methods on embedded docs?

瘦欲@ 提交于 2019-12-11 09:49:06
问题 How can I run aggregate, min, max, sum and friends on embedded docs? For example: Get the average cost of ALL events that a district has, where they are pretty deeply embedded. District.schools.all.events.all.costs.avg(:value) Obviously doesn't work. District.avg('schools.events.costs.value') Neither does that. It gives this error message: Mongo::OperationFailure: Database command 'group' failed: (errmsg: 'exception: reduce invoke failed: JS Error: TypeError: obj.schools has no properties

Mongoid 4: like query on integer column

那年仲夏 提交于 2019-12-11 09:29:44
问题 I need a mongoid search like query with INTEGER COLUMN . For example: SELECT * FROM users WHERE mobile LIKE '%9980%'; Here is the my model: class User include Mongoid::Document include Mongoid::Timestamps ## # Columns field :name, type: String field :mobile, type: Integer end I already tried following examples. But no luck :( User.where(:$where => "/^#{params[:mobile]}/") User.any_of({mobile: /.*#{params[:mobile]}.*/i}) User.where(mobile: /8801/)) How to write it with mongoid? 回答1: Try this

Carrierwave_Direct's direct_upload_form_for returns undefined method `model_name' for FileUploader:Class

て烟熏妆下的殇ゞ 提交于 2019-12-11 08:35:24
问题 I've been struggling with this for a couple of hours now. When using carrierwave_direct's direct_upload_form_for in my view, it returns me this error: FileUploader Carrierwave Class: class FileUploader < CarrierWave::Uploader::Base include CarrierWaveDirect::Uploader end ManualFile Model: class ManualFile include Mongoid::Document mount_uploader :file, FileUploader field :name, :type => String end UploadController: class UploadController < ApplicationController def manual_new @uploader =

ActionView::Template::Error (no implicit conversion of Fixnum into String on heroku

懵懂的女人 提交于 2019-12-11 07:21:53
问题 I am working on ROR app with Mongodb.App is working fine on localhost, but when i deploy it in heroku i am getting error. One of my view file command is this: @h=Portfolio.last.folders <%= @h%> The Portfolio is a collection with field folders as array. Mongodb on production contain this. Even i try do same in heroku rails console I got the same error which is : TypeError: no implicit conversion of Fixnum into String from /app/vendor/bundle/ruby/2.0.0/gems/moped-1.4.3/lib/moped/protocol