Giter Site home page Giter Site logo

benedikt / mongoid-tree Goto Github PK

View Code? Open in Web Editor NEW
302.0 7.0 69.0 420 KB

A tree structure for Mongoid documents using the materialized path pattern

Home Page: https://www.rubydoc.info/github/benedikt/mongoid-tree

License: MIT License

Ruby 100.00%

mongoid-tree's Introduction

mongoid-tree Build Status

A tree structure for Mongoid documents using the materialized path pattern

Requirements

  • mongoid (>= 4.0, < 10.0)

For a mongoid 3.x compatible version, please use mongoid-tree 1.0.x, for a mongoid 2.x compatible version, please use mongoid-tree 0.7.x.

Install

To install mongoid_tree, simply add it to your Gemfile:

gem 'mongoid-tree', require: 'mongoid/tree'

In order to get the latest development version of mongoid-tree:

gem 'mongoid-tree', git: 'git://github.com/benedikt/mongoid-tree', branch: :main

You might want to add require: nil option and explicitly require 'mongoid/tree' where needed and finally run

bundle install

Upgrade from mongoid-tree 1.x

To fix issues with the ordering of ancestors, mongoid-tree 2.0 introduces a new depth field to the documents that include the Mongoid::Tree module. In case your project uses its own depth field, you can now rely on mongoid-tree to handle this.

Usage

Read the API documentation at https://www.rubydoc.info/github/benedikt/mongoid-tree and take a look at the Mongoid::Tree module

class Node
  include Mongoid::Document
  include Mongoid::Tree
end

Utility methods

There are several utility methods that help getting to other related documents in the tree:

Node.root
Node.roots
Node.leaves

node.root
node.parent
node.children
node.ancestors
node.ancestors_and_self
node.descendants
node.descendants_and_self
node.siblings
node.siblings_and_self
node.leaves

In addition it's possible to check certain aspects of the document's position in the tree:

node.root?
node.leaf?
node.depth
node.ancestor_of?(other)
node.descendant_of?(other)
node.sibling_of?(other)

See Mongoid::Tree for more information on these methods.

Ordering

Mongoid::Tree doesn't order children by default. To enable ordering of tree nodes include the Mongoid::Tree::Ordering module. This will add a position field to your document and provide additional utility methods:

node.lower_siblings
node.higher_siblings
node.first_sibling_in_list
node.last_sibling_in_list

node.move_up
node.move_down
node.move_to_top
node.move_to_bottom
node.move_above(other)
node.move_below(other)

node.at_top?
node.at_bottom?

Example:

class Node
  include Mongoid::Document
  include Mongoid::Tree
  include Mongoid::Tree::Ordering
end

See Mongoid::Tree::Ordering for more information on these methods.

Traversal

It's possible to traverse the tree using different traversal methods using the Mongoid::Tree::Traversal module.

Example:

class Node
  include Mongoid::Document
  include Mongoid::Tree
  include Mongoid::Tree::Traversal
end

node.traverse(:breadth_first) do |n|
  # Do something with Node n
end

Destroying

Mongoid::Tree does not handle destroying of nodes by default. However it provides several strategies that help you to deal with children of deleted documents. You can simply add them as before_destroy callbacks.

Available strategies are:

  • :nullify_children -- Sets the children's parent_id to null
  • :move_children_to_parent -- Moves the children to the current document's parent
  • :destroy_children -- Destroys all children by calling their #destroy method (invokes callbacks)
  • :delete_descendants -- Deletes all descendants using a database query (doesn't invoke callbacks)

Example:

class Node
  include Mongoid::Document
  include Mongoid::Tree

  before_destroy :nullify_children
end

Callbacks

There are two callbacks that are called before and after the rearranging process. This enables you to do additional computations after the documents position in the tree is updated. See Mongoid::Tree for details.

Example:

class Page
  include Mongoid::Document
  include Mongoid::Tree

  after_rearrange :rebuild_path

  field :slug
  field :path

  private

  def rebuild_path
    self.path = self.ancestors_and_self.collect(&:slug).join('/')
  end
end

Validations

Mongoid::Tree currently does not validate the document's children or parent associations by default. To explicitly enable validation for children and parent documents it's required to add a validates_associated validation.

Example:

class Node
  include Mongoid::Document
  include Mongoid::Tree

  validates_associated :parent, :children
end

Build Status

mongoid-tree is on GitHub Actions running the specs on Ruby 3.1-3.3 and Mongoid 4.x-9.x.

Known issues

See https://github.com/benedikt/mongoid-tree/issues

Repository

See https://github.com/benedikt/mongoid-tree and feel free to fork it!

Contributors

See a list of all contributors at https://github.com/benedikt/mongoid-tree/contributors. Thanks a lot everyone!

Copyright

Copyright (c) 2010-2024 Benedikt Deicke. See LICENSE for details.

mongoid-tree's People

Contributors

adzuci avatar asgerb avatar benedikt avatar gurix avatar jimneath avatar madwire avatar neongrau avatar nickhoffman avatar olleolleolle avatar ream88 avatar semaperepelitsa avatar tomk32 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

mongoid-tree's Issues

ancestors sorting

Hello

Have met curious issue with "ancestors" method returning incorrectly sorted array.
I see that the $or query is used for building this list, and it does not sort, and shouldn't actually.

My certain case:

cat = Category.find "51df059033e53b0c18000014"
cat.ancestors.collect(&:_id)
 => [BSON::ObjectId('51df024e33e53b0c18000004'), BSON::ObjectId('51939bfb33e53b9808000001')]

Having following entries

{
    "_id" : ObjectId("51df059033e53b0c18000014"),
    "parent_id" : ObjectId("51df024e33e53b0c18000004"),
    "parent_ids" : [
        ObjectId("51939bfb33e53b9808000001"),
        ObjectId("51df024e33e53b0c18000004")
    ],
    "position" : 0,
    "slug" : "cars"
}
{
    "_id" : ObjectId("51df024e33e53b0c18000004"),
    "parent_id" : ObjectId("51939bfb33e53b9808000001"),
    "parent_ids" : [
        ObjectId("51939bfb33e53b9808000001")
    ],
    "position" : 2,
    "slug" : "transportation"
}
{
    "_id" : ObjectId("51939bfb33e53b9808000001"),
    "parent_ids" : [ ],
    "position" : 0,
    "slug" : "/"
}

The whole setup is the following:

  • Ruby 2.0.0p0
  • MongoDB 2.4.8
  • mongoid 4.0.0
  • mongoid-tree 1.0.4

Not compatible with rails 4

Bundler could not find compatible versions for gem "activemodel":   
  In Gemfile:                                                       
    mongoid-tree (>= 0) ruby depends on                             
      activemodel (~> 3.0.0.beta) ruby                              

    rails (= 4.0.0) ruby depends on                                 
      activemodel (4.0.0)                                           

Mongoid::Errors::DocumentNotFound

class ArticleCategory
include Mongoid::Document
include Mongoid::Tree
include Mongoid::Timestamps
end

p = ArticleCategory.new
c = ArticleCategory.new

p.children << c
p.save

Mongoid::Errors::DocumentNotFound: Document not found for class ArticleCategory with id(s) 4cbf3fb1a27d2013bf000006 ( actually p id )

undefined method `parent_ids' for nil:NilClass

Using mongoid (3.0.9)

Using mongoid-tree (1.0.1)

Rails Method is throwing

def rebuild_path

MassTopic.all.each do |topic|
  puts "Buliding Path: " + topic.name
  topic.path = topic.ancestors_and_self.collect{ |item| "#{item.name}||#{item.id}"}.join("$$")

  topic.save

end
respond_to do |format|
  format.html { render :text => "Done"}
end

end

[2012-11-05 21:28:24] ERROR NoMethodError: undefined method parent_ids' for nil:NilClass /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-tree-1.0.1/lib/mongoid/tree.rb:420:inrearrange'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-tree-1.0.1/lib/mongoid/tree.rb:95:in block (3 levels) in <module:Tree>' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:403:in_run__2708834019810802991__rearrange__21207758887223718__callbacks'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in __run_callback' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in_run_rearrange_callbacks'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in run_callbacks' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/callbacks.rb:114:inrun_callbacks'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-tree-1.0.1/lib/mongoid/tree.rb:95:in block (2 levels) in <module:Tree>' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:407:in_run__2708834019810802991__validation__21207758887223718__callbacks'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in __run_callback' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in_run_validation_callbacks'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:in run_callbacks' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/callbacks.rb:114:inrun_callbacks'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activemodel-3.2.8/lib/active_model/validations/callbacks.rb:53:in run_validations!' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activemodel-3.2.8/lib/active_model/validations.rb:194:invalid?'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/validations.rb:78:in valid?' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activemodel-3.2.8/lib/active_model/validations.rb:202:ininvalid?'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/persistence/modification.rb:22:in prepare' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/persistence/operations/update.rb:43:inpersist'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/persistence.rb:139:in update' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/persistence.rb:81:insave'
/home/ec2-user/apps/testtree/app/controllers/homes_controller.rb:48:in block in rebuild_path' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/contextual/mongo.rb:644:inyield_document'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/contextual/mongo.rb:134:in block (2 levels) in each' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/moped-1.2.7/lib/moped/query.rb:78:inblock in each'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/moped-1.2.7/lib/moped/cursor.rb:26:in block in each' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/moped-1.2.7/lib/moped/cursor.rb:26:ineach'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/moped-1.2.7/lib/moped/cursor.rb:26:in each' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/moped-1.2.7/lib/moped/query.rb:77:ineach'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/moped-1.2.7/lib/moped/query.rb:77:in each' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/contextual/mongo.rb:133:inblock in each'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/contextual/mongo.rb:603:in selecting' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/contextual/mongo.rb:132:ineach'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/contextual.rb:18:in each' /home/ec2-user/apps/testtree/app/controllers/homes_controller.rb:37:inrebuild_path'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_controller/metal/implicit_render.rb:4:in send_action' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/abstract_controller/base.rb:167:inprocess_action'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_controller/metal/rendering.rb:10:in process_action' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/abstract_controller/callbacks.rb:18:inblock in process_action'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:414:in _run__1342489903615171212__process_action__184040716227805675__callbacks' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in__run_callback'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in _run_process_action_callbacks' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:inrun_callbacks'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/abstract_controller/callbacks.rb:17:in process_action' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_controller/metal/rescue.rb:29:inprocess_action'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_controller/metal/instrumentation.rb:30:in block in process_action' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:inblock in instrument'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/notifications/instrumenter.rb:20:in instrument' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/notifications.rb:123:ininstrument'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_controller/metal/instrumentation.rb:29:in process_action' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_controller/metal/params_wrapper.rb:207:inprocess_action'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/abstract_controller/base.rb:121:in process' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/abstract_controller/rendering.rb:45:inprocess'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_controller/metal.rb:203:in dispatch' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_controller/metal/rack_delegation.rb:14:indispatch'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_controller/metal.rb:246:in block in action' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:73:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:73:in dispatch' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:36:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/journey-1.0.4/lib/journey/router.rb:68:in block in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/journey-1.0.4/lib/journey/router.rb:56:ineach'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/journey-1.0.4/lib/journey/router.rb:56:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/routing/route_set.rb:600:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/rack/mongoid/middleware/identity_map.rb:33:in block in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/mongoid/unit_of_work.rb:39:inunit_of_work'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/mongoid-3.0.9/lib/rack/mongoid/middleware/identity_map.rb:33:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/sass-3.2.1/lib/sass/plugin/rack.rb:54:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/best_standards_support.rb:17:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/etag.rb:23:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/conditionalget.rb:25:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/head.rb:14:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/params_parser.rb:21:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/flash.rb:242:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:205:in context' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/session/abstract/id.rb:200:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/cookies.rb:339:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/callbacks.rb:28:inblock in call'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in _run__1883085759501563229__call__21207758887223718__callbacks' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:405:in__run_callback'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:385:in _run_call_callbacks' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/callbacks.rb:81:inrun_callbacks'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/callbacks.rb:27:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/remote_ip.rb:31:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/debug_exceptions.rb:16:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/show_exceptions.rb:56:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/rack/logger.rb:26:in call_app' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/rack/logger.rb:16:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/request_id.rb:22:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/methodoverride.rb:21:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/runtime.rb:17:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/activesupport-3.2.8/lib/active_support/cache/strategy/local_cache.rb:72:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/lock.rb:15:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/actionpack-3.2.8/lib/action_dispatch/middleware/static.rb:62:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/engine.rb:479:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/application.rb:223:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/content_length.rb:14:in call' /home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/railties-3.2.8/lib/rails/rack/log_tailer.rb:17:incall'
/home/ec2-user/.rvm/gems/ruby-1.9.3-p286/gems/rack-1.4.1/lib/rack/handler/webrick.rb:59:in service' /home/ec2-user/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/webrick/httpserver.rb:138:inservice'
/home/ec2-user/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/webrick/httpserver.rb:94:in run' /home/ec2-user/.rvm/rubies/ruby-1.9.3-p286/lib/ruby/1.9.1/webrick/server.rb:191:inblock in start_thread'

License missing from gemspec

Some companies will only use gems with a certain license.
The canonical and easy way to check is via the gemspec
via e.g.

spec.license = 'MIT'
# or
spec.licenses = ['MIT', 'GPL-2']

There is even a License Finder to help companies ensure all gems they use
meet their licensing needs. This tool depends on license information being available in the gemspec.
Including a license in your gemspec is a good practice, in any case.

How did I find you?

I'm using a script to collect stats on gems, originally looking for download data, but decided to collect licenses too,
and make issues for missing ones as a public service :)
https://gist.github.com/bf4/5952053#file-license_issue-rb-L13 So far it's going pretty well

Mongoid Tree Ordering error in Rails 4

Hi, i get this Problem: Defining a scope of value #Mongoid::Criteria:0x007f0fd89fa800 on Page is not allowed. Summary: Scopes in Mongoid must be procs that wrap criteria objects. Resolution: Change the scope to be a proc wrapped critera. Example: class Band include Mongoid::Document scope :inactive, ->{ where(active: false) } end

I think it doesn't like line "default_scope asc(:position)" in ordering.rb

Im using ruby 2.0.0-p451, Rails 4.0.2 ( tried to run in rails 4.0.0, same thing)

Thank you in advance.

defaullt scope is evil!

I found this gem and for me that was been awesome before I spent a lot of time to find sorting bug in my query.

        default_scope ->{ asc(:position) }

I think that must be removed ...

Mongo::InvalidSortValueError

The plugin worked fine and flawless (thx for that!) until I upgraded to rails3.1 and in the course of that, also to mongoid-tree-0.6.0 and mongoid-2.0.2: Now I'm getting a

 Mongo::InvalidSortValueError:
       Mongo::Support was supplied as a sort direction when acceptable values are: Mongo::ASCENDING, 'ascending', 'asc', :ascending, :asc, 1, Mongo::DESCENDING, 'descending', 'desc', :descending, :desc, -1.

which I tracked down to ordering.rb, line 38:

default_scope asc(:position)

If I comment this one out, the error vanishes, but of course also the ordering. I'm not yet sure, which change in which lib caused the default_scope to stop working with an ordering, but maybe someone else has an idea?

PS: default_scope as(:my_field) works fine when directly included in a model, so maybe it has something to with ActiveSupport::Concern (wild guess...)?

with mongoid 3.0.0.rc

Updating git://github.com/benedikt/mongoid-tree
Fetching source index for http://rubygems.org/
Bundler could not find compatible versions for gem "mongoid":
In Gemfile:
mongoid-tree (>= 0) ruby depends on
mongoid (~> 2.0) ruby

mongoid (3.0.0.rc)

Problem destroying

When running @thing.destroy I get a wrong number of arguments (2 for 1) error with the following stack trace:

lib/mongoid/persistable/incrementable.rb:23:in `inc'
mongoid-tree (1.0.1) lib/mongoid/tree/ordering.rb:200:in `block in move_lower_siblings_up'
lib/mongoid/contextual/mongo.rb:640:in `yield_document'
lib/mongoid/contextual/mongo.rb:123:in `block (2 levels) in each'
moped (1.4.5) lib/moped/query.rb:77:in `block in each'
...

Can not get depth value

I am writing following method:

def rebuild_path
self.path = self.ancestors_and_self.collect{ |item| "#{item.name}||#{item.id}||#{item.depth}"}.join("$$")
end

I am not able to get depth value in #{item.depth}

Please help!

Regards,
Abhishek

Cascading :rearrange callbacks

Not sure if this is an issue, but if a model has

embeds_many :something, cascade_callbacks: true

Then the embedded model (something) has to have

define_model_callbacks :rearrange

otherwise it throws an exception undefined method _run_rearrange_callbacks when callbacks are run.

Runtime dependency issue

Hi,

seems like mongoid-tree can't be used in combination with mongoid v3, since mongoid-tree is depending on mongoid v2.

Is it possible to update the runtime dependency or is mongoid-tree incompatible with mongoid 3?

Does not work under mongoid 2.0.0.rc.1

There is an error when server starts:
ruby-1.9.2-p136/gems/mongoid-tree-0.5.0/lib/mongoid/tree/ordering.rb:36:in `block in module:Ordering': You have a nil object when you didn't expect it! (NoMethodError)
You might have expected an instance of Array.
The error occurred while evaluating nil.[]=

Mongoid 2.0.1 dependency

Hi! I want to use mongoid-tree for project I'm working on. I'm having this problem...

My Gemfile:
...
gem 'mongoid', :git => 'git://github.com/mongoid/mongoid.git'
gem 'mongoid-tree', :git => 'git://github.com/benedikt/mongoid-tree', :require => 'mongoid/tree'
...

And dependency problem...

Bundler could not find compatible versions for gem "mongoid":
  In Gemfile:
    mongoid-tree depends on
      mongoid (~> 2.0.0)

    mongoid (2.1.0)

The Ordering Module Causes Errors with Mongoid 3.0.9

When I include the Ordering module into a model with Mongoid 3.0.9, this query https://github.com/benedikt/mongoid-tree/blob/master/lib/mongoid/tree/ordering.rb#L204 causes a MongoDB error when I try to create the model:

failed with error 16052: "exception: could not create cursor over test.catalog_categories for query : { deleted_at: null, site_id: 1, parent_id: null, _id: { $ne: ObjectId('507824caace6ecd9140017fe') } } sort : { position: 1 }"

Demo

I have re/searched round 6 hours now to get this thing working but I messed up.

How are these functions to use?

node.root
node.parent
node.children
node.ancestors
......
....
..
.

In Controller? Or Model?

Is my "node" the model I am dealing with?

FOR ALL: How to SAVE a children?

Please help me out with a simple RealWorld example

many, many thanks in advance

Mongoid 3.0.10 and mongoid-tree 1.0.1 does not save children

Hi Benedikt,

yesterday I updated my app from mongoid 2.4 to mongoid 3.0.10.

my gemfile has

gem 'mongoid-tree', :require => 'mongoid/tree'

The root Categories were saved correctly but the children are not saved anymore.

def create

unless params[:category][:parent_ids].blank?
  @category = Category.find(params[:category][:parent_ids])
  params[:category].delete :parent_ids
  @category.children.build(params[:category])
else
  params[:category].delete :parent_ids
  @category = Category.new(params[:category])

end
  respond_to do |format|
    if @category.save!
      format.html { redirect_to @category, notice: 'Category was successfully created.' }
      format.json { render json: @category, status: :created, location: @category }
    else
      format.html { render action: "new" }
      format.json { render json: @category.errors, status: :unprocessable_entity }
    end
    end
  end

any suggestions?

thank you :-)

Can't use ".ancestors" in combination with third part code like ".acessible_by" from CanCan

Fixing issue #39 had a bad sideffect in combination with CanCan. So we add in some cases acessible_by(....) that filters out some objects because of insufficient user permissions.

It looks like that:

 x.ancestors.accessible_by(current_ability).desc(:created_at)

This has resulted in the following criteria:

=> #<Mongoid::Criteria
  selector: {"deleted_at"=>nil, "_id"=>{"$in"=>["523c01d2cb7a24d7d4000511"]}, "$or"=>[{"privacy"=>"public"}, {"user_id"=>"523c01bdcb7a24d7d400014d"}]}
  options:  {:sort=>{"created_at"=>-1}}
  class:    Foo
  embedded: false>

Your fix changed the selector to

=> #<Mongoid::Criteria
  selector: {"deleted_at"=>nil, "$or"=>[{"_id"=>"523c01d2cb7a24d7d4000511"}, {"privacy"=>"public"}, {"user_id"=>"523c01bdcb7a24d7d400014d"}]}
  options:  {:sort=>{"created_at"=>-1}}
  class:    Foo
  embedded: false>

A quick solution was to change the query to

Foo.in(id: x.parent_ids).accessible_by(current_ability).desc(:created_at)

I can't decide whether it is really a bug or a false implementation from my side or rather CanCan. Any ideas?

Make mongoid-tree work with Ruby 1.9.2

It seems that some functionality is broken in Ruby 1.9.2 . Eg: http://pastie.org/1323370

I'm going through ordering.rb , and some of the logic seems a bit wonky to me. For example, #move_below calls
other.lower_siblings.where(:position.lt => self.position).each { |s| s.inc(:position, 1) }
but don't as far as I can tell, the arguments to #where in #lower_siblings oppose what's specified on the line above.
def lower_siblings
self.siblings.where(:position.gt => self.position)
end

# It's impossible for a value to be > and < another value.
# :position.gt => self.position # from #lower_siblings
# :position.lt => self.position  # from #move_below

Error on 'destroy_all' with 'before_destroy :move_children_to_parent' enabled

Having before_destroy :move_children_to_parent in model I tried to delete all documents with destroy_all but it failed with error:

rake aborted!
undefined method `parent_ids' for nil:NilClass
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-tree-1.0.3/lib/mongoid/tree.rb:424:in `rearrange'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-tree-1.0.3/lib/mongoid/tree.rb:95:in `block (3 levels) in <module:Tree>'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:403:in `_run__633100963__rearrange__138057480__callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_rearrange_callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/callbacks.rb:130:in `run_callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-tree-1.0.3/lib/mongoid/tree.rb:95:in `block (2 levels) in <module:Tree>'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:407:in `_run__633100963__validation__138057480__callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_validation_callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/callbacks.rb:130:in `run_callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activemodel-3.2.13/lib/active_model/validations/callbacks.rb:53:in `run_validations!'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activemodel-3.2.13/lib/active_model/validations.rb:195:in `valid?'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/validations.rb:84:in `valid?'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activemodel-3.2.13/lib/active_model/validations.rb:203:in `invalid?'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/persistence/modification.rb:22:in `prepare'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/persistence/operations/update.rb:45:in `persist'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/persistence.rb:145:in `update'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/persistence.rb:82:in `save'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-tree-1.0.3/lib/mongoid/tree.rb:394:in `block in move_children_to_parent'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/relations/referenced/many.rb:169:in `block in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/relations/targets/enumerable.rb:184:in `block in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:640:in `yield_document'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:123:in `block (2 levels) in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/query.rb:77:in `block in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/cursor.rb:26:in `block in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/cursor.rb:26:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/cursor.rb:26:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/query.rb:76:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/query.rb:76:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:122:in `block in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:619:in `selecting'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:121:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual.rb:19:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/relations/targets/enumerable.rb:181:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/relations/referenced/many.rb:169:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-tree-1.0.3/lib/mongoid/tree.rb:392:in `move_children_to_parent'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:407:in `_run__633100963__destroy__138057480__callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_destroy_callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/callbacks.rb:130:in `run_callbacks'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/persistence.rb:34:in `destroy'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/persistence.rb:324:in `block in destroy_all'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:640:in `yield_document'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:123:in `block (2 levels) in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/query.rb:77:in `block in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/cursor.rb:26:in `block in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/cursor.rb:26:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/cursor.rb:26:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/query.rb:76:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/moped-1.5.0/lib/moped/query.rb:76:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:122:in `block in each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:619:in `selecting'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual/mongo.rb:121:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/contextual.rb:19:in `each'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/gems/mongoid-3.1.4/lib/mongoid/persistence.rb:324:in `destroy_all'
/home/laise/Work/gid72/lib/tasks/gid43/categories_seed.rake:25:in `seed'
/home/laise/Work/gid72/lib/tasks/gid43/categories_seed.rake:34:in `block (3 levels) in <top (required)>'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/bin/ruby_noexec_wrapper:14:in `eval'
/home/laise/.rvm/gems/ruby-1.9.3-p448@gid72/bin/ruby_noexec_wrapper:14:in `<main>'
Tasks: TOP => gid43:categories:seed
(See full trace by running task with --trace)

[support] How best to embed tree in another document?

Thanks for Mongoid::Tree; it's just what I was looking for. I'm new to Ruby, Rails and Mongo so it helps a lot. I just asked this question on Stackoverflow too and realized I should ask here too.

I want a tree of nodes and I want the whole tree to be embedded in another document. My problem is that this really only requires that the root node be embedded but all nodes have the same embedded_in. In my case:

class Container
  include Mongoid::Document

  embeds_one :root, :class_name => "Node"
end

class Node
  include Mongoid::Document
  include Mongoid::Tree

  embedded_in :container, :inverse_of => :root
end

How can I set this up so that only one record per tree is embedded_in the Container? Is there another approach that would be better?

parent could not be empty on creation

Hi Benedict,

I have mongoid v6.0.0.beta with Ruby on Rails 5.0.0 running (perfectly at the time :-) ),
but I have troubles with the 'parent_id' and it's validation:

Here is my model

class Role
  include Mongoid::Document
  include Mongoid::Tree

  field :name, type: String

  has_and_belongs_to_many :users

  validates_presence_of :name
end


Role.create!(name: "test")

which causes:

Mongoid::Errors::Validations: 
message:
  Validation of Role failed.
summary:
  The following errors were found: Parent Parent could not be empty
resolution:
  Try persisting the document with valid data or remove the validations.


Any suggestions to solve that?

Thank you very much!

Mongoid::Errors::InvalidPath

Crosspost from: https://github.com/mongoid/mongoid/issues/3595


Hello,

in my app I have a model Node which is powered by mongoid-tree to create a simple tree structure and mongoid-versioning (which is basically just an extraction of the old Mongoid::Versioning module).

When I'm creating a new child Node like so:

parent = Node.create
node = Node.create parent: parent

I get following error:

Mongoid::Errors::InvalidPath: 
Problem:
  Having a root path assigned for Node is invalid.
Summary:
  Mongoid has two different path objects for determining the location of a document in the database, Root and Embedded. This error is raised when an embedded document somehow gets a root path assigned.
Resolution:
  Most likely your embedded model, Node is also referenced via a has_many from a root document in another collection. Double check the relation definitions and fix any instances where embedded documents are improperly referenced from other collections.

Any idea how to fix this? I created a test app here: https://gist.github.com/haihappen/10354578

Compatibility naming

Hi, @benedikt.

Is there a way to name the relationships something else than parent and children? Being able to name them something else would greatly ease the migration process, since my existing project names these relationships something very specific (business domain reasons).

Large collection problem

I have very large tree about 1,8 milion docs. Everything was OK until I tried to change structure of the tree.
For example when I want to change parent of some root I have to wait minutes.
Is it normal?

Can't seem to get mongoid-tree working with any of the rc versions of mongoid

class Category
  include Mongoid::Document
  include Mongoid::Tree
  include Mongoid::Tree::Traversal

  field :name
end
c = Category.create(:name => 'test1')
c.children << Category.new(:name => 'test2')
c.save
puts Category.first.children.to_a.inspect

= []

The above works with the beta mongoid versions I have tried.

Is it possible to have a parent with a child of a different class?

Let's say I have two mongoid models....
'''ruby
class Company
include Mongoid::Document
include Mongoid::Tree

field :name, type: String
field :address, type: String
end

class Container
include Mongoid::Document
include Mongoid::Tree
include Mongoid::Tree::Traversal

field :name, type: String

end
'''
When I create a Container, I can easily add children with something like...

'''ruby
parent = Container.find(params[:id])
parent.children.create

But when trying to create a company that is a child of a container I do something like this...

@company = Company.new(params[:company])
  root = Container.find(id)
  root.children << @company
  root.save
  @company.save

'''
It seems to work as when I output the company's info it has the parent id, but doing something like @company.parent returns nil. Is there a way to do this or can trees only contain children of the same class as the parent? If it is possible how would I traverse such? Thanks in advance.

Mongoid::Tree::Ordering results in error 16052: "exception: could not create cursor..." when calling x.children.max(:position)

I have added Mongoid::Tree::Ordering to my folder model, but now I can't call max(:position) anymore:

folder.children.max(:position)

This results in:

Moped::Errors::OperationFailure at /de/admin/folders/52401f0e77bb1edcea0001a3/folders/new
The operation: #<Moped::Protocol::Command
  @length=1052
  @request_id=112
  @response_to=0
  @op_code=2004
  @flags=[:slave_ok]
  @full_collection_name="iq_development.$cmd"
  @skip=0
  @limit=-1
  @selector={:mapreduce=>"folders", :map=>"\n          function() {\n            var agg = {\n              count: 1,\n              max: this.position,\n              min: this.position,\n              sum: this.position\n            };\n            emit(\"position\", agg);\n          }", :reduce=>"\n          function(key, values) {\n            var agg = { count: 0, max: null, min: null, sum: 0 };\n            values.forEach(function(val) {\n              if (val.max !== null) {\n                if (agg.max == null || val.max > agg.max) agg.max = val.max;\n                if (agg.min == null || val.max < agg.min) agg.min = val.max;\n                agg.sum += val.sum;\n              }\n              agg.count += val.count;\n            });\n            return agg;\n          }", :query=>{"deleted_at"=>nil, "client_id"=>"52401f0b77bb1edcea0000cc", "parent_id"=>"52401f0e77bb1edcea0001a2"}, :sort=>{"position"=>1}, :out=>{:inline=>1}, :finalize=>"\n          function(key, agg) {\n            agg.avg = agg.sum / agg.count;\n            return agg;\n          }"}
  @fields=nil>
failed with error 16052: "exception: could not create cursor over iq_development.folders for query : { deleted_at: null, client_id: ObjectId('52401f0b77bb1edcea0000cc'), parent_id: ObjectId('52401f0e77bb1edcea0001a2') } sort : { position: 1 }"

See https://github.com/mongodb/mongo/blob/master/docs/errors.md
for details about this error.

Any idea what's going on here?

Unscope only position

I'm using Mongoid::Tree::ordering module and applying default scope on documents. I also want to re-order documents while keeping default scope except position. However, it seems that the default scope position in Mongoid::Tree::ordering has higher priority to my ordering.

Unscoping is a solution, but it loses other default scoping. Is there any way to unscope only position?

I'm new to mongo, please pardon my uninitiating question

warning deprecation on latest rubygems

NOTE: Gem::Specification#has_rdoc= is deprecated with no replacement. It will be removed on or after 2011-10-01.
Gem::Specification#has_rdoc= called from /Users/Pibefision/.rvm/gems/ruby-1.9.2-p180/bundler/gems/mongoid-tree-d82d2177306b/mongoid-tree.gemspec:11

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.