All Projects → kobil-systems → Mongodb

kobil-systems / Mongodb

Licence: apache-2.0
MongoDB driver for Elixir

Programming Languages

elixir
2628 projects

Projects that are alternatives of or similar to Mongodb

Mongo Cxx Driver
C++ Driver for MongoDB
Stars: ✭ 792 (+71.06%)
Mutual labels:  mongodb, driver
Objcmongodb
Mac OS and iOS library for MongoDB and BSON
Stars: ✭ 166 (-64.15%)
Mutual labels:  mongodb, driver
Reactivemongo
🍃 Non-blocking, Reactive MongoDB Driver for Scala
Stars: ✭ 825 (+78.19%)
Mutual labels:  mongodb, driver
Phpfastcache
A high-performance backend cache system. It is intended for use in speeding up dynamic web applications by alleviating database load. Well implemented, it can drops the database load to almost nothing, yielding faster page load times for users, better resource utilization. It is simple yet powerful.
Stars: ✭ 2,171 (+368.9%)
Mutual labels:  mongodb, driver
Cachego
Golang Cache component - Multiple drivers
Stars: ✭ 148 (-68.03%)
Mutual labels:  mongodb, driver
Qmgo
Qmgo - The Go driver for MongoDB. It‘s based on official mongo-go-driver but easier to use like Mgo.
Stars: ✭ 444 (-4.1%)
Mutual labels:  mongodb, driver
Youtube Clone Nodejs Api
VueTube is a YouTube clone built with nodejs, expressjs & mongodb. This is the RESTful API repository.
Stars: ✭ 441 (-4.75%)
Mutual labels:  mongodb
Mongo Php Adapter
🔗 Adapter to provide ext-mongo interface on top of mongo-php-library
Stars: ✭ 453 (-2.16%)
Mutual labels:  mongodb
Private Project
一些基于React、Vue、Node.js、MongoDB技术栈的实践项目
Stars: ✭ 438 (-5.4%)
Mutual labels:  mongodb
Vj4
The online judge service with millions of submissions, since 2005.
Stars: ✭ 430 (-7.13%)
Mutual labels:  mongodb
Api Design Node V3
[Course] API design in Node with Express v3
Stars: ✭ 459 (-0.86%)
Mutual labels:  mongodb
Fullstack Javascript
Source code for the Fullstack JavaScript book
Stars: ✭ 456 (-1.51%)
Mutual labels:  mongodb
Dsefix
Windows x64 Driver Signature Enforcement Overrider
Stars: ✭ 448 (-3.24%)
Mutual labels:  driver
Buji Pac4j
pac4j security library for Shiro: OAuth, CAS, SAML, OpenID Connect, LDAP, JWT...
Stars: ✭ 444 (-4.1%)
Mutual labels:  mongodb
Wdbgark
WinDBG Anti-RootKit Extension
Stars: ✭ 450 (-2.81%)
Mutual labels:  driver
Meantorrent
meanTorrent - MEAN.JS BitTorrent Private Tracker - Full-Stack JavaScript Using MongoDB, Express, AngularJS, and Node.js, A BitTorrent Private Tracker CMS with Multilingual, and IRC announce support, CloudFlare support. Demo at:
Stars: ✭ 438 (-5.4%)
Mutual labels:  mongodb
Mongodb Json Files
📦 A curated list of JSON / BSON datasets from the web in order to practice / use in MongoDB
Stars: ✭ 456 (-1.51%)
Mutual labels:  mongodb
Opentabletdriver
Open source, cross-platform, user-mode tablet driver
Stars: ✭ 424 (-8.42%)
Mutual labels:  driver
Middleware development learning
中间件、高性能服务器、分布式存储等(redis、memcache、nginx、大容量redis pika、rocksdb、mongodb、wiredtiger存储引擎、高性能代理中间件)二次开发、性能优化,逐步整理文档说明并配合demo指导--每周末定时更新2-3篇技术文章及程序demo--(技术交流QQ群:568892619)
Stars: ✭ 449 (-3.02%)
Mutual labels:  mongodb
Bdp Dataplatform
大数据生态解决方案数据平台:基于大数据、数据平台、微服务、机器学习、商城、自动化运维、DevOps、容器部署平台、数据平台采集、数据平台存储、数据平台计算、数据平台开发、数据平台应用搭建的大数据解决方案。
Stars: ✭ 456 (-1.51%)
Mutual labels:  mongodb

MongoDB

Build Status

Documentation for MongoDB is available online.

Features

  • Supports MongoDB versions 3.4, 3.6, 4.0
  • Connection pooling (through db_connection)
  • Streaming cursors
  • Performant ObjectID generation
  • Follows driver specification set by 10gen
  • Safe (by default) and unsafe writes
  • Aggregation pipeline
  • Replica sets
  • Sessions and transactions

Immediate Roadmap

  • Make sure requests don't go over the 16 MiB limit
  • New 2.6 write queries and bulk writes

Tentative Roadmap

Data representation

BSON Elixir
double 0.0
string "Elixir"
document [{"key", "value"}] | %{"key" => "value"} ¹
binary %BSON.Binary{binary: <<42, 43>>, subtype: :generic}
object id %BSON.ObjectId{value: <<...>>}
boolean true
UTC datetime %DateTime{}
null nil
regex %BSON.Regex{pattern: "..."}
JavaScript %BSON.JavaScript{code: "..."}
integer 42
symbol "foo" ²
min key :BSON_min
max key :BSON_max

¹ Since BSON documents are ordered Elixir maps cannot be used to fully represent them. This driver chose to accept both maps and lists of key-value pairs when encoding but will only decode documents to maps. This has the side-effect that the information about order of keys in a BSON document is lost when it's decoded. Additionally the driver will accept both atoms and strings for document keys but will only decode to strings.

² BSON symbols can only be decoded.

Writing your own encoding info

If you want to write a custom struct to your mongo collection - you can do that by implementing Mongo.Encoder protocol for your class. The output should be a map, which will be passed to the Mongo database.

Example:

defmodule CustomStruct do
  @fields [:a, :b, :c, :id]
  @enforce_keys @fields
  defstruct @fields

  defimpl Mongo.Encoder do
    def encode(%{a: a, b: b, id: id}) do
      %{
        _id: id,
        a: a,
        b: b,
        custom_encoded: true
      }
    end
  end
end

So, given the struct:

%CustomStruct{a: 10, b: 20, c: 30, id: "5ef27e73d2a57d358f812001"}

it will be written to database, as:

{
  "a": 10,
  "b": 20,
  "custom_encoded": true,
  "_id": "5ef27e73d2a57d358f812001"
}

Usage

Installation:

Add mongodb to your mix.exs deps.

defp deps do
  [
    {:mongodb, "~> 0.5.1"}
  ]
end

Then run mix deps.get to fetch dependencies.

Connection pooling

By default mongodb will start a single connection, but it also supports pooling with the :pool_size option.

# Starts an unpooled connection
{:ok, conn} = Mongo.start_link(url: "mongodb://localhost:27017/db-name")

# Gets an enumerable cursor for the results
cursor = Mongo.find(conn, "test-collection", %{})

cursor
|> Enum.to_list()
|> IO.inspect

If you're using pooling it is recommend to add it to your application supervisor:

def start(_type, _args) do
  children = [
    {Mongo, [name: :mongo, database: "test", pool_size: 2]}
  ]

  opts = [strategy: :one_for_one, name: MyApp.Supervisor]
  Supervisor.start_link(children, opts)
end

Simple start with pooling:

{:ok, conn} = Mongo.start_link(name: :mongo, database: "test", pool_size: 2)

Operate the mongodb with specify pool name in each query:

Mongo.find(:mongo, "collection", %{}, limit: 20)

More pool options in here.

Replica Sets

To connect to a MongoDB cluster that is using replica sets, it is recommended to use the :seeds list instead of a :hostname and :port pair.

{:ok, pid} = Mongo.start_link(database: "test", seeds: ["hostname1.net:27017", "hostname2.net:27017"])

This will allow for scenarios where the first "hostname1.net:27017" is unreachable for any reason and will automatically try to connect to each of the following entries in the list to connect to the cluster.

Auth mechanisms

For versions of MongoDB 3.0 and greater, the auth mechanism defaults to SCRAM. If you'd like to use MONGODB-X509 authentication, you can specify that as a start_link option.

{:ok, pid} = Mongo.start_link(database: "test", auth_mechanism: :x509)

AWS, TLS and Erlang SSL ciphers

Some MongoDB cloud providers (notably AWS) require a particular TLS cipher that isn't enabled by default in the Erlang SSL module. In order to connect to these services, you'll want to add this cipher to your ssl_opts:

{:ok, pid} = Mongo.start_link(database: "test",
      ssl_opts: [
        ciphers: ['AES256-GCM-SHA384'],
        cacertfile: "...",
        certfile: "...")
      ]
)

Examples

Using $and

Mongo.find(:mongo, "users", %{"$and" => [%{email: "[email protected]"}, %{first_name: "first_name"}]})

Using $or

Mongo.find(:mongo, "users", %{"$or" => [%{email: "[email protected]"}, %{first_name: "first_name"}]})

Using $in

Mongo.find(:mongo, "users", %{email: %{"$in" => ["[email protected]", "[email protected]"]}})

Contributing

The SSL test suite is enabled by default. You have two options. Either exclude the SSL tests or enable SSL on your MongoDB server.

Disable the SSL tests

mix test --exclude ssl

Enable SSL on your Mongo server

$ openssl req -newkey rsa:2048 -new -x509 -days 365 -nodes -out mongodb-cert.crt -keyout mongodb-cert.key
$ cat mongodb-cert.key mongodb-cert.crt > mongodb.pem
$ mongod --sslMode allowSSL --sslPEMKeyFile /path/to/mongodb.pem
  • For --sslMode you can use one of allowSSL or preferSSL
  • You can enable any other options you want when starting mongod

License

Copyright 2015 Justin Wood and Kobil Systems GmbH

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].