Giter Club home page Giter Club logo

mongox's Introduction

MongoX - DEPRECATED

Build Status Coveralls Coverage Inline docs

Deprecation Notice

TLDR; Please use https://github.com/ankhers/mongodb.

This is an unmaintained fork of ankhers/mongodb which was made to support replica sets at a time when the original repo did not. ankhers/mongodb now offers full replica set support and is being actively maintained.

Features

  • Full Replica Set Support
  • Supports MongoDB versions 2.4, 2.6, 3.0, 3.2
  • Connection pooling
  • Streaming cursors
  • Performant ObjectID generation
  • Follows driver specification set by 10gen
  • Safe (by default) and unsafe writes
  • Aggregation pipeline

Immediate Roadmap

  • Add timeouts for all calls
  • Bang and non-bang Mongo functions
  • Move BSON encoding to client process
    • Make sure requests don't go over the 16mb limit
  • Replica sets
    • Block in client (and timeout) when waiting for new primary selection
  • New 2.6 write queries and bulk writes
  • Reconnect backoffs with https://github.com/ferd/backoff
  • Lazy connect ? Drop save_* because it was dropped by driver specs

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 | false
UTC datetime        %BSON.DateTime{utc: ...}
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 lists. This has the side-effect that it's impossible to discern empty arrays from empty documents. Additionally the driver will accept both atoms and strings for document keys but will only decode to strings.

** BSON symbols can only be decoded.

Usage

Connection Pools

defmodule MongoPool do
  use Mongo.Pool, name: __MODULE__, adapter: Mongo.Pool.Poolboy
end

# Starts the pool named MongoPool
{:ok, _} = MongoPool.start_link(database: "test")

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

Enum.to_list(cursor)
|> IO.inspect

Examples

Mongo.find(MongoPool, "test-collection", %{}, limit: 20)
Mongo.find(MongoPool, "test-collection", %{"field" => %{"$gt" => 0}}, limit: 20, sort: %{"field" => 1})

Mongo.insert_one(MongoPool, "test-collection", %{"field" => 10})

Mongo.insert_many(MongoPool, "test-collection", [%{"field" => 10}, %{"field" => 20}])

Mongo.delete_one(MongoPool, "test-collection", %{"field" => 10})

Mongo.delete_many(MongoPool, "test-collection", %{"field" => 10})

License

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.

mongox's People

Contributors

ericmj avatar emerleite avatar michalmuskala avatar rockerboo avatar skalmus avatar boriscy avatar hectorip avatar jocko avatar mindreframer avatar bernardolins avatar johnnyshields avatar

Stargazers

Niranjan Anandkumar avatar  avatar Mateus Pontes avatar  avatar  avatar Michal Valasek avatar Paul A. avatar  avatar Tiago Guedes avatar Ianko Leite avatar  avatar Nick avatar

Watchers

 avatar  avatar HugoLnx avatar James Cloos avatar  avatar

mongox's Issues

Merge back to ericmj/mongodb?

Hi emerleite, just wondering what's preventing merging these changes back into ericmj/mongodb? MongoDB support in Elixir is fairly sparse and would be great if efforts could be pooled into one repo.

Timeout not working

You can set timeout on the config but it's not working it uses te default 5000

Investigate query timeout on Ecto.get_by

** (EXIT) time out
Server: example.com:80 (http)
14:45:44.926 [error] #PID<0.8956.1> running App.Endpoint terminated
Request: POST /myroute/
** (exit) exited in: GenServer.call(#PID<0.1822.0>, {:find, "user_resource_lists", [{"$query", ["$and": [["$and": [["$and": [[list_name: "watch_history"], [resource_id: 5350643]]], [user_origin: "cadun"]]], [user_id: "64893283"]]]}, {"$orderby", %{}}], %{_id: true, created_at: true, fully_watched: true, list_name: true, milliseconds_watched: true, program_id: true, resource_id: true, updated_at: true, user_id: true, user_origin: true}, [batch_size: 1000]}, 5000)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.