mongo~sam-x

Bindings for MongoDB C Driver
0.3.1 Yanked release released
sam0x17/mongo.cr
3
Sam Johnson

mongo.cr

Build Status

This library provides binding for MongoDB C Driver. The goal is to provide a driver to access MongoDB.

Status

Release

Requirements

  • Crystal language version 0.34.0 and higher.
  • libmongoc version 1.16.2+
  • libbson verion 1.16.2+

On Mac OSX use homebrew to install the required libraries:

$ brew install mongo-c

On Linux you need to install libmongoc-1.16-2 and libbson-1.16-2 from your package manager or from source:

wget https://github.com/mongodb/mongo-c-driver/releases/download/1.16.2/mongo-c-driver-1.16.2.tar.gz
tar -zxvf mongo-c-driver-1.16.2.tar.gz && cd mongo-c-driver-1.16.2/
cmake -DENABLE_AUTOMATIC_INIT_AND_CLEANUP=OFF
sudo make install

See the official guide.

Installation

Add this to your application's shard.yml:

mongo:
  github: datanoise/mongo.cr
  branch: master

Usage

require "mongo"

client = Mongo::Client.new "mongodb://<user>:<password>@<host>:<port>/<db_name>"
db = client["db_name"]

collection = db["collection_name"]
collection.insert({ name: "James Bond", age: 37 })

collection.find({ age: { "$gt": 30 }}) do |doc|
  puts typeof(doc)    # => BSON
  puts doc
end

Use compile time flag -Duse_mongo_static to use libbson-static-1.0 and libmongoc-static-1.0 if you encounter the following error:

/root/.cache/crystal/crystal-run-spec.tmp: error while loading shared libraries: libmongoc-1.0.so.0: cannot open shared object file: No such file or directory

License

MIT clause - see LICENSE for more details.

mongo:
  github: sam0x17/mongo.cr
  version: ~> 0.3.1
License MIT
Crystal 0.34.0

Authors

Libraries 1

  • libmongoc: ~> 1.16.2

Dependencies 0

Development Dependencies 1

  • dotenv
    {'github' => 'gdotdesign/cr-dotenv'}

Dependents 1

Last synced .
search fire star recently