Class: Daru::IO::Importers::Mongo
- Defined in:
- lib/daru/io/importers/mongo.rb
Overview
Mongo Importer Class, that extends from_mongo
method to Daru::DataFrame
Class Method Summary collapse
-
.from(connection) ⇒ Daru::IO::Importers::Mongo
Loads data from a given connection.
Instance Method Summary collapse
-
#call(collection, *columns, order: nil, index: nil, filter: nil, limit: nil, skip: nil, **named_columns) ⇒ Daru::DataFrame
Imports a
Daru::DataFrame
from a Mongo Importer instance. -
#from(connection) ⇒ Daru::IO::Importers::Mongo
Loads data from a given connection.
-
#initialize ⇒ Mongo
constructor
Checks for required gem dependencies of Mongo Importer.
Methods inherited from JSON
Methods inherited from Base
Methods inherited from Base
Constructor Details
#initialize ⇒ Mongo
Checks for required gem dependencies of Mongo Importer
11 12 13 14 |
# File 'lib/daru/io/importers/mongo.rb', line 11 def initialize super optional_gem 'mongo' end |
Class Method Details
.from(connection) ⇒ Daru::IO::Importers::Mongo
Loads data from a given connection
33 34 35 36 |
# File 'lib/daru/io/importers/mongo.rb', line 33 def from(connection) @client = get_client(connection) self end |
Instance Method Details
#call(collection, *columns, order: nil, index: nil, filter: nil, limit: nil, skip: nil, **named_columns) ⇒ Daru::DataFrame
Note:
- For more information on using JSON-path selectors, have a look at the explanations here and here.
- The Mongo gem faces
Argument Error : expected Proc Argument
issue due to the bug in MRI Ruby 2.4.0 mentioned here. This seems to have been fixed in Ruby 2.4.1 onwards. Hence, please avoid using this Mongo Importer in Ruby version 2.4.0.
Imports a Daru::DataFrame
from a Mongo Importer instance.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/daru/io/importers/mongo.rb', line 107 def call(collection, *columns, order: nil, index: nil, filter: nil, limit: nil, skip: nil, **named_columns) @json = ::JSON.parse( @client[collection.to_sym] .find(filter, skip: skip, limit: limit) .to_json ) super(*columns, order: order, index: index, **named_columns) end |
#from(connection) ⇒ Daru::IO::Importers::Mongo
Loads data from a given connection
33 34 35 36 |
# File 'lib/daru/io/importers/mongo.rb', line 33 def from(connection) @client = get_client(connection) self end |