class ROM::Mongo::Dataset
Attributes
collection[R]
criteria[R]
Public Class Methods
new(collection, criteria = Criteria.new)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 10 def initialize(collection, criteria = Criteria.new) @collection = collection @criteria = criteria end
Public Instance Methods
each() { |doc| ... }
click to toggle source
@api private
# File lib/rom/mongo/dataset.rb, line 28 def each view.each { |doc| yield(doc) } end
find(criteria = {})
click to toggle source
# File lib/rom/mongo/dataset.rb, line 19 def find(criteria = {}) Dataset.new(collection, Criteria.new.where(criteria)) end
insert(data)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 32 def insert(data) collection.insert_one(data) end
limit(limit)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 56 def limit(limit) dataset(criteria.limit(limit)) end
only(fields)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 48 def only(fields) dataset(criteria.only(fields)) end
order(value)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 64 def order(value) dataset(criteria.order(value)) end
remove_all()
click to toggle source
# File lib/rom/mongo/dataset.rb, line 40 def remove_all view.delete_many end
skip(value)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 60 def skip(value) dataset(criteria.skip(value)) end
to_a()
click to toggle source
# File lib/rom/mongo/dataset.rb, line 23 def to_a view.to_a end
update_all(attributes)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 36 def update_all(attributes) view.update_many(attributes) end
where(doc)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 44 def where(doc) dataset(criteria.where(doc)) end
without(fields)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 52 def without(fields) dataset(criteria.without(fields)) end
Private Instance Methods
dataset(criteria)
click to toggle source
# File lib/rom/mongo/dataset.rb, line 74 def dataset(criteria) Dataset.new(collection, criteria) end
view()
click to toggle source
# File lib/rom/mongo/dataset.rb, line 70 def view with_options(collection.find(criteria.selector), criteria.options) end
with_options(view, options)
click to toggle source
Applies given options to the view
@api private
# File lib/rom/mongo/dataset.rb, line 81 def with_options(view, options) map = { fields: :projection } options.each do |option, value| option = map.fetch(option, option) view = view.send(option, value) if view.respond_to?(option) end view end