New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jmuheim opened this Issue Sep 23, 2013 · 7 comments

Comments

Projects
None yet
2 participants
@jmuheim

jmuheim commented Sep 23, 2013

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?

@benedikt

This comment has been minimized.

Owner

benedikt commented Sep 23, 2013

Hi Joshua,

thanks for reporting this issue. I don't have an idea what's happening just from looking at the error. I tried to reproduce it, but did not have any success, yet. Can you share some details about the versions of MongoDB, Mongoid and Mongoid-Tree you're using?

Thanks!

Benedikt

@jmuheim

This comment has been minimized.

jmuheim commented Sep 23, 2013

mongoid (3.0.22)
mongoid-tree (1.0.4)
MongoDB shell version: 2.2.0

@jmuheim

This comment has been minimized.

jmuheim commented Sep 23, 2013

# encoding: utf-8
class Folder
  include Mongoid::Document
  include Mongoid::Timestamps
  include Mongoid::Paranoia
  include Mongoid::Tree
  include Mongoid::Multitenancy::Document
  include Mongoid::Orderable

  orderable scope: :parent_id

  tenant :client
end

Could there be some problem with the combination with Mongoid::Orderable?

@benedikt

This comment has been minimized.

Owner

benedikt commented Sep 23, 2013

There could indeed be a problem with having moth Mongoid::Tree::Ordering and Mongoid::Orderable in place. Have you tried removing Mongoid::Orderable?

@jmuheim

This comment has been minimized.

jmuheim commented Sep 23, 2013

I removed Orderable, but this didn't seem to do the trick.

I also noticed that has_many :activity_types, order: {position: 1} causes a similar problem. Maybe there's something else not good and it doesn't have to do with the Tree gem?

@benedikt

This comment has been minimized.

Owner

benedikt commented Sep 23, 2013

Hm… that indeed looks like there's another issue not directly related to the mongoid-tree gem. Would you mind investigating a little more? Please don't hesitate to get back to me as soon as you discover that it is in fact related to mongoid-tree.

@jmuheim

This comment has been minimized.

jmuheim commented Sep 23, 2013

I will look into it a bit deeper as soon as I find time. Thanks for your replies.

@benedikt benedikt closed this Jul 21, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment