Sha256: 008059e34419701a1737a861bb75f59815fe8b90a43c3f7b23bbb47ad0b5d301

Contents?: true

Size: 780 Bytes

Versions: 2

Compression:

Stored size: 780 Bytes

Contents

require 'mongodoc'

class Contact
  attr_accessor :name, :addresses, :interests
end

class Address
  attr_accessor :street, :city, :state, :zip, :phone_number
end

MongoDoc.connect_to_database 'test'

collection = MongoDoc::Collection.new('contacts')
collection.drop

contact = Contact.new
contact.name = 'Hashrocket'
contact.interests = ['ruby', 'rails', 'agile']

address = Address.new
address.street = '320 First Street North, #712'
address.city = 'Jacksonville Beach'
address.state = 'FL'
address.zip = '32250'
address.phone_number = '877 885 8846'
contact.addresses = [address]

collection.save(contact)

results = collection.find('addresses.state' => 'FL')
hashrocket = results.to_a.find {|contact| contact.name == 'Hashrocket'}
puts hashrocket.addresses.first.phone_number

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
mongodoc-0.2.1 examples/simple_object.rb
mongodoc-0.2.0 examples/simple_object.rb