Sha256: 472134e7cf217883e9d72681783f24e5d2029d07f560d88aa8c4c808bd5dc010
Contents?: true
Size: 1020 Bytes
Versions: 1
Compression:
Stored size: 1020 Bytes
Contents
require 'mongo' module MongoClient class << self # @return Client to work with MongoDb attr_accessor :client def insert(model, data, id) collection = MongoClient.client[model] collection.insert_one({ id: id, data: data}) end def find(model, id) collection = MongoClient.client[model] collection.find( { id: id } ).first end def get_all(model) collection = MongoClient.client[model] collection.find.collect { |match| match } end def find_all(model, query) collection = MongoClient.client[model] collection.find( query ).collect { |match| match } end def update(model, id, data) collection = MongoClient.client[model] collection.update_one({ id: id }, { '$set' => data }) end def delete(model, id) collection = MongoClient.client[model] collection.delete_one({ id: id }) end end end MongoClient.client = Mongo::Client.new( [ "#{ENV['mongodb']}:27017" ], :database => 'api')
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
schemaless_rest_api-0.2.0 | lib/schemaless_rest_api/mongo_client.rb |