0.0
The project is in a healthy, maintained state
MongoDB adapter for Ruby Object Mapper
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 3.13
~> 2.21
~> 13.1

Runtime

~> 2.19, >= 2.19.3
~> 5.2
 Project Readme

MongoDB adapter for Ruby Object Mapper

Maintainability Test Coverage CircleCI Gem Version Downloads GitHub Contributor Covenant

rom-mongodb - MongoDB adapter for ROM. What is ROM? It's a fast ruby persistence library with the goal of providing powerful object mapping capabilities without limiting the full power of the underlying datastore.

Table of Contents

  • Requirements
  • Installation
  • Usage
  • Contributing
  • License
  • Code of Conduct
  • Credits
  • Versioning
  • Changelog

Requirements

Ruby MRI 2.5.0+

Installation

Add this line to your application's Gemfile:

gem 'rom-mongodb'

And then execute:

bundle

Or install it yourself as:

gem install rom-mongodb

Usage

# Define your container with mongo adapter

require 'mongo'
require 'rom'
require 'rom/mongo'

connection = Mongo::Client.new('mongodb://127.0.0.1:27017/your_db_name')
container = ROM.container(:mongo, connection) do |config|
  config.relation(:users) do
    schema(:users) do
      attribute :_id, ROM::Types.Nominal(BSON::ObjectId)
      attribute :email, ROM::Types::String
      attribute :rating, ROM::Types::Integer
      attribute :status, ROM::Types::Bool
      attribute :orders?, ROM::Types::Array # optional attribute, if field does not exists will return nil
    end
  end
end

# Define your repository

require 'rom/repository'

UserRepository = ::Class.new(ROM::Repository[:users]) do
  commands(:create, :delete, update: :by_pk)

  def all
    users.to_a
  end

  def find(**options)
    users.find(options)
  end
end

user_repository = UserRepository.new(container)

# Now you can do some manipulations with your repository

user_repository.create({ email: 'olo@domain.com', rating: 42, status: true })
user_repository.all
user_repository.find(email: 'olo@domain.com')

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/bestwebua/rom-mongo. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct. Please check the open tickets. Be sure to follow Contributor Code of Conduct below and our Contributing Guidelines.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the rom-mongodb project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Credits

Versioning

rom-mongodb uses Semantic Versioning 2.0.0