Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

sorting requires indexes; namespace issues are gone

  • Loading branch information...
commit 940c7e2c97c1d9f487871f28a5525d96cf8e9783 1 parent 961ceec
Aman Gupta authored

Showing 1 changed file with 20 additions and 31 deletions. Show diff stats Hide diff stats

  1. 51  rmongo.rb
51  rmongo.rb
@@ -266,6 +266,11 @@ def desc
266 266
   mongo.insert(:_id => '000000000000000000000014', :n => 5, :object => { :boolean => true })
267 267
   mongo.insert(:_id => '000000000000000000000015', :n => 6, :symbol => :Constant)
268 268
 
  269
+  # add index on n
  270
+  mongo.namespace('default.system.indexes') do
  271
+    mongo.insert(:name => 'n', :ns => 'default.test', :key => { :n => true })
  272
+  end
  273
+
269 274
   # simple searches
270 275
   mongo.find(:n > 1) do |results|
271 276
     
@@ -276,7 +281,7 @@ def desc
276 281
     
277 282
   end
278 283
 
279  
-  # sorting # XXX why doesn't this work
  284
+  # sorting # XXX requires an index to sort
280 285
   mongo.find({}, :n.desc) do |results|
281 286
     
282 287
   end
@@ -293,7 +298,7 @@ def desc
293 298
   mongo.insert(:_id => '000000000000000000000103', :name => :eclipse,  :platform => [:osx, :linux, :windows])
294 299
   mongo.insert(:_id => '000000000000000000000104', :name => :notepad,  :platform => [:windows])
295 300
   
296  
-  # find all editors # XXX why does this find objects outside the namespace
  301
+  # find all editors
297 302
   mongo.find({}) do |results|
298 303
     
299 304
   end
@@ -387,41 +392,25 @@ def desc
387 392
 
388 393
 --------------------------------------------------------------------------------
389 394
 
390  
-FIND {:orderby=>{:n=>-1}, :query=>{:n=>{:$gt=>0}}} => # XXX why doesn't this work
  395
+FIND {:orderby=>{:n=>-1}, :query=>{}} =>
391 396
 
392  
-[{:_id=>"000000000000000000000010", :array=>[1.0, 2.0, 3.0], :n=>1.0},
393  
- {:_id=>"000000000000000000000011", :n=>2.0, :string=>"ruby and js"},
394  
- {:_id=>"000000000000000000000012", :number=>112233.445566, :n=>3.0},
395  
- {:_id=>"000000000000000000000013", :n=>4.0, :null=>nil},
396  
- {:_id=>"000000000000000000000014", :n=>5.0, :object=>{:boolean=>true}},
397  
- {:_id=>"000000000000000000000015", :adf=>"123", :n=>6.0}]
  397
+[{:symbol=>:Constant, :n=>6.0, :_id=>"000000000000000000000015"},
  398
+ {:object=>{:boolean=>true}, :n=>5.0, :_id=>"000000000000000000000014"},
  399
+ {:null=>nil, :n=>4.0, :_id=>"000000000000000000000013"},
  400
+ {:number=>112233.445566, :n=>3.0, :_id=>"000000000000000000000012"},
  401
+ {:n=>2.0, :_id=>"000000000000000000000011", :string=>"ruby and js"},
  402
+ {:array=>[1.0, 2.0, 3.0], :n=>1.0, :_id=>"000000000000000000000010"}]
398 403
 
399 404
 --------------------------------------------------------------------------------
400 405
 
401  
-FIND {} => # XXX why does this find objects outside the namespace
  406
+FIND {} =>
402 407
 
403  
-[{:_id=>"000000000000000000000001", :hello=>"world"},
404  
- {:_id=>"000000000000000000000002",
405  
-  :hash=>{:boolean=>true},
406  
-  :regex=>/abc$/ix,
407  
-  :float=>123.456,
408  
-  :symbol=>:name,
409  
-  :array=>[1.0, 2.0, 3.0],
410  
-  :nil=>nil,
411  
-  :string=>"hello world",
412  
-  :time=>Sat Aug 02 02:08:27 -0700 2008},
413  
- {:_id=>"000000000000000000000010", :array=>[1.0, 2.0, 3.0], :n=>1.0},
414  
- {:_id=>"000000000000000000000011", :n=>2.0, :string=>"ruby and js"},
415  
- {:_id=>"000000000000000000000012", :number=>112233.445566, :n=>3.0},
416  
- {:_id=>"000000000000000000000013", :n=>4.0, :null=>nil},
417  
- {:_id=>"000000000000000000000014", :n=>5.0, :object=>{:boolean=>true}},
418  
- {:_id=>"000000000000000000000015", :adf=>"123", :n=>6.0},
419  
- {:_id=>"000000000000000000000101", :name=>:textmate, :platform=>[:osx]},
420  
- {:_id=>"000000000000000000000102", :name=>:vim, :platform=>[:osx, :linux]},
421  
- {:_id=>"000000000000000000000103",
422  
-  :name=>:eclipse,
  408
+[{:name=>:textmate, :_id=>"000000000000000000000101", :platform=>[:osx]},
  409
+ {:name=>:vim, :_id=>"000000000000000000000102", :platform=>[:osx, :linux]},
  410
+ {:name=>:eclipse,
  411
+  :_id=>"000000000000000000000103",
423 412
   :platform=>[:osx, :linux, :windows]},
424  
- {:_id=>"000000000000000000000104", :name=>:notepad, :platform=>[:windows]}]
  413
+ {:name=>:notepad, :_id=>"000000000000000000000104", :platform=>[:windows]}]
425 414
 
426 415
 --------------------------------------------------------------------------------
427 416
 

0 notes on commit 940c7e2

Please sign in to comment.
Something went wrong with that request. Please try again.