Class: Faststep::Collection
- Inherits:
-
Object
- Object
- Faststep::Collection
- Defined in:
- lib/faststep/collection.rb,
ext/faststep/collection.c
Instance Attribute Summary collapse
-
#db ⇒ Object
readonly
Returns the value of attribute db.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #connection ⇒ Object
- #count ⇒ Object
- #create_index ⇒ Object
- #drop ⇒ Object
- #drop_index(index_name) ⇒ Object
- #find ⇒ Object
- #find_one ⇒ Object
- #index_information ⇒ Object
-
#initialize(name, db) ⇒ Collection
constructor
A new instance of Collection.
- #insert ⇒ Object
- #ns ⇒ Object
- #remove ⇒ Object
- #rename(new_name) ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(name, db) ⇒ Collection
Returns a new instance of Collection.
5 6 7 8 |
# File 'lib/faststep/collection.rb', line 5 def initialize(name, db) @name = name @db = db end |
Instance Attribute Details
#db ⇒ Object (readonly)
Returns the value of attribute db.
3 4 5 |
# File 'lib/faststep/collection.rb', line 3 def db @db end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
3 4 5 |
# File 'lib/faststep/collection.rb', line 3 def name @name end |
Instance Method Details
#connection ⇒ Object
10 11 12 |
# File 'lib/faststep/collection.rb', line 10 def connection db.connection end |
#count ⇒ Object
#create_index ⇒ Object
#drop ⇒ Object
#drop_index(index_name) ⇒ Object
31 32 33 34 |
# File 'lib/faststep/collection.rb', line 31 def drop_index(index_name) db.command(:deleteIndexes => self.name, :index => index_name) true end |
#find ⇒ Object
#find_one ⇒ Object
#index_information ⇒ Object
14 15 16 17 18 19 20 |
# File 'lib/faststep/collection.rb', line 14 def index_information info = {} db["system.indexes"].find({:ns => ns}).each do |index| info[index['name']] = index end info end |
#insert ⇒ Object
#ns ⇒ Object
#remove ⇒ Object
#rename(new_name) ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/faststep/collection.rb', line 22 def rename(new_name) command = BSON::OrderedHash.new command[:renameCollection] = ns command[:to] = "#{db.name}.#{new_name}" connection["admin"].command(command) @name = new_name true end |