Sha256: be461c8e9d87ae0551b3666b846d445927c19eb61c4effc97a9751fdd86f617e

Contents?: true

Size: 1.35 KB

Versions: 14

Compression:

Stored size: 1.35 KB

Contents

#!/usr/bin/env ruby

require File.join(File.dirname(__FILE__), '_common.rb')

include XGen::Mongo

db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB)
x = db.collection('x')
y = db.collection('y')

def sorted_index_info(c)
  c.index_information.sort { |a,b| a[:name] <=> b[:name] }
end

def sorted_info_keys(info)
  info[:keys].keys.sort.collect { |key| "#{key}_1" }.join("_")
end

def check_keys(c, expected)
  keys = sorted_index_info(c).collect {|info| sorted_info_keys(info)}
  if keys == expected
    ''
  else
    "#{c.name} indices should start out #{expected.inspect} but is #{keys.inspect}"
  end
end

if $DEBUG
  x.drop                        # also drops indexes
  x.insert('field1' => 'f1', 'field2' => 'f2')
  x.create_index('field1_1', 'field1')
  x.create_index('field2_1', 'field2')
  y.drop
end

# There should only be two indices on x, and none on y. We raise an error if
# the preconditions are not met. (They were not, on our testing harness, for a
# while due to Mongo behavior.)
err = []
err << check_keys(x, ['field1_1', 'field2_1'])
err << check_keys(y, [])
raise "\n#{err.join("\n")}" unless err == ['', '']

x.drop_index('field1_1')
sorted_index_info(x).each { |info| puts sorted_info_keys(info) }

y.create_index([['a', ASCENDING], ['b', ASCENDING], ['c', ASCENDING]])
y.create_index('d')
sorted_index_info(y).each { |info| puts sorted_info_keys(info) }

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
animehunter-mongo-0.9 tests/mongo-qa/indices
mongodb-mongo-0.10.1 tests/mongo-qa/indices
mongodb-mongo-0.10 tests/mongo-qa/indices
mongodb-mongo-0.11.1 tests/mongo-qa/indices
mongodb-mongo-0.11 tests/mongo-qa/indices
mongodb-mongo-0.12 tests/mongo-qa/indices
mongodb-mongo-0.6.3 tests/mongo-qa/indices
mongodb-mongo-0.6.4 tests/mongo-qa/indices
mongodb-mongo-0.6.5 tests/mongo-qa/indices
mongodb-mongo-0.6.6 tests/mongo-qa/indices
mongodb-mongo-0.6.7 tests/mongo-qa/indices
mongodb-mongo-0.7 tests/mongo-qa/indices
mongodb-mongo-0.8 tests/mongo-qa/indices
mongodb-mongo-0.9 tests/mongo-qa/indices