Module mongo

Top-level client interface to MongoDB.

Description

Top-level client interface to MongoDB

Data Types

action()

action(A) = fun(() -> A)

An Action does IO, reads process dict {mongo_action_context, #context{}}, and throws failure()

batchsize()

batchsize() = integer()

collection()

collection() = atom()

command()

command() = mongo_query:command()

connection()

connection() = mongo_connect:connection()

cursor()

cursor() = mongo_cursor:cursor()

db()

db() = atom()

error_code()

error_code() = integer()

failure()

failure() = mongo_connect:failure() | mongo_query:not_master() | write_failure() | mongo_cursor:expired()

host()

host() = mongo_connect:host()

Hostname or ip address with or without port. Port defaults to 27017 when missing. Eg. "localhost" or {"localhost", 27017}

index_uniqueness()

index_uniqueness() = non_unique | unique | unique_dropdups

key_order()

key_order() = bson:document()

List keys and whether ascending (1) or descending (-1). Eg. {x,1, y,-1}

maybe()

maybe(A) = {A} | {}

modifier()

modifier() = bson:document()

projector()

projector() = bson:document()

read_mode()

read_mode() = master | slave_ok

Every query inside an action() will use this mode. master = Server must be master/primary so reads are consistent (read latest writes). slave_ok = Server may be slave/secondary so reads may not be consistent (may read stale data). Slaves will eventually get the latest writes, so technically this is called eventually-consistent.

reason()

reason() = any()

replset()

replset() = mongo_replset:replset()

rs_connection()

rs_connection() = mongo_replset:rs_connection()

selector()

selector() = bson:document()

skip()

skip() = integer()

write_failure()

write_failure() = {write_failure, error_code(), bson:utf8()}

write_mode()

write_mode() = unsafe | safe | {safe, mongo_query:getlasterror_request()}

Every write inside an action() will use this write mode. unsafe = asynchronous write (no reply) and hence may silently fail; safe = synchronous write, wait for reply and fail if connection or write failure; {safe, Params} = same as safe but with extra params for getlasterror, see its documentation.

Function Index

close_cursor/1Close cursor.
command/1Execute given MongoDB command and return its result.
connect/1Connect to given MongoDB server.
connect_factory/1Factory for use with a connection pool.
count/2Count selected documents.
count/3Count selected documents up to given max number; 0 means no max.
create_index/2Create non-unique index on given keys in collection.
create_index/3Create index on given keys with given uniqueness.
create_index/4Create index on given keys with given uniqueness and name.
delete/2Delete selected documents.
delete_one/2Delete first selected document.
disconnect/1Close connection to server.
do/5Execute mongo action under given write_mode, read_mode, connection, and db.
find/2Return selected documents.
find/3Return projection of selected documents.
find/4Return projection of selected documents starting from Nth document.
find/5Return projection of selected documents starting from Nth document in batches of batchsize.
find_one/2Return first selected document, if any.
find_one/3Return projection of first selected document, if any.
find_one/4Return projection of Nth selected document, if any.
insert/2Insert document into collection.
insert_all/2Insert documents into collection.
modify/3Update all documents selected using modifier.
next/1Return next document in query result cursor, if any.
replace/3Replace first document selected with given document.
repsert/3Replace first document selected with given document, or insert it if selection is empty.
rest/1Return remaining documents in query result cursor.
rs_connect/1Create new cache of connections to replica set members starting with seed members.
rs_connect_factory/1Factory for use with a rs_connection pool.
rs_disconnect/1Close cache of replset connections.
save/2If document has no '_id' field then insert it, otherwise update it and insert only if missing.

Function Details

connect/1

connect(Host::host()) -> {ok, connection()} | {error, reason()}

Connect to given MongoDB server

disconnect/1

disconnect(Conn::connection()) -> ok

Close connection to server

connect_factory/1

connect_factory(Host::host()) -> resource_pool:factory(connection())

Factory for use with a connection pool. See resource_pool module.

rs_connect/1

rs_connect(Replset::replset()) -> rs_connection()

Create new cache of connections to replica set members starting with seed members. No connection attempted until rs_primary or rs_secondary_ok called.

rs_disconnect/1

rs_disconnect(ReplsetConn::rs_connection()) -> ok

Close cache of replset connections

rs_connect_factory/1

rs_connect_factory(Replset::replset()) -> resource_pool:factory(rs_connection())

Factory for use with a rs_connection pool. See resource_pool module.

do/5

do(WriteMode::write_mode(), ReadMode::read_mode(), Connection::connection() | rs_connection(), Database::db(), Action::action(A)) -> {ok, A} | {failure, failure()}

Execute mongo action under given write_mode, read_mode, connection, and db. Return action result or failure.

insert/2

insert(Coll::collection(), Doc::bson:document()) -> bson:value()

Insert document into collection. Return its '_id' value, which is auto-generated if missing.

insert_all/2

insert_all(Coll::collection(), Docs::[bson:document()]) -> [bson:value()]

Insert documents into collection. Return their '_id' values, which are auto-generated if missing.

save/2

save(Coll::collection(), Doc::bson:document()) -> ok

If document has no '_id' field then insert it, otherwise update it and insert only if missing.

replace/3

replace(Coll::collection(), Selector::selector(), Doc::bson:document()) -> ok

Replace first document selected with given document.

repsert/3

repsert(Coll::collection(), Selector::selector(), Doc::bson:document()) -> ok

Replace first document selected with given document, or insert it if selection is empty.

modify/3

modify(Coll::collection(), Selector::selector(), Mod::modifier()) -> ok

Update all documents selected using modifier

delete/2

delete(Coll::collection(), Selector::selector()) -> ok

Delete selected documents

delete_one/2

delete_one(Coll::collection(), Selector::selector()) -> ok

Delete first selected document.

find_one/2

find_one(Coll::collection(), Selector::selector()) -> maybe(bson:document())

Return first selected document, if any

find_one/3

find_one(Coll::collection(), Selector::selector(), Projector::projector()) -> maybe(bson:document())

Return projection of first selected document, if any. Empty projection [] means full projection.

find_one/4

find_one(Coll::collection(), Selector::selector(), Projector::projector(), Skip::skip()) -> maybe(bson:document())

Return projection of Nth selected document, if any. Empty projection [] means full projection.

find/2

find(Coll::collection(), Selector::selector()) -> cursor()

Return selected documents.

find/3

find(Coll::collection(), Selector::selector(), Projector::projector()) -> cursor()

Return projection of selected documents. Empty projection [] means full projection.

find/4

find(Coll::collection(), Selector::selector(), Projector::projector(), Skip::skip()) -> cursor()

Return projection of selected documents starting from Nth document. Empty projection means full projection.

find/5

find(Coll::collection(), Selector::selector(), Projector::projector(), Skip::skip(), BatchSize::batchsize()) -> cursor()

Return projection of selected documents starting from Nth document in batches of batchsize. 0 batchsize means default batch size. Negative batch size means one batch only. Empty projection means full projection.

next/1

next(Cursor::cursor()) -> maybe(bson:document())

Return next document in query result cursor, if any.

rest/1

rest(Cursor::cursor()) -> [bson:document()]

Return remaining documents in query result cursor.

close_cursor/1

close_cursor(Cursor::cursor()) -> ok

Close cursor

count/2

count(Coll::collection(), Selector::selector()) -> integer()

Count selected documents

count/3

count(Coll::collection(), Selector::selector(), Limit::integer()) -> integer()

Count selected documents up to given max number; 0 means no max. Ie. stops counting when max is reached to save processing time.

command/1

command(Command::command()) -> bson:document()

Execute given MongoDB command and return its result.

create_index/2

create_index(Coll::collection(), KeyOrder::key_order()) -> ok

Create non-unique index on given keys in collection

create_index/3

create_index(Coll::collection(), KeyOrder::key_order(), Uniqueness::index_uniqueness()) -> ok

Create index on given keys with given uniqueness

create_index/4

create_index(Coll::collection(), KeyOrder::key_order(), Uniqueness::index_uniqueness(), IndexName::bson:utf8()) -> ok

Create index on given keys with given uniqueness and name


Generated by EDoc, May 24 2011, 13:17:09.