Module db_mongo

This module implements a higher level wrapper for mongodb. Example:
import mongo, db_mongo, oids, json

var conn = db_mongo.open()

# construct JSON data:
var data = %{"a": %13, "b": %"my string value",
             "inner": %{"i": %71} }

var id = insertID(conn, "test.test", data)

for v in find(conn, "test.test", "this.a == 13"):
  print v

delete(conn, "test.test", id)
close(conn)

Types

EDb* = object of EIO
exception that is raised if a database error occurs
TDbConn* = TMongo
a database connection; alias for TMongo

Procs

proc dbError*(db: TDbConn; msg: string) {.noreturn.}
raises an EDb exception with message msg.
proc Close*(db: var TDbConn)
closes the database connection.
proc Open*(host: string = defaultHost; port: int = defaultPort): TDbConn
opens a database connection. Raises EDb if the connection could not be established.
proc jsonToBSon*(j: PJsonNode; oid: TOid): TBSon
converts a JSON value into the BSON format. The result must be destroyed explicitely!
proc `[]`*(obj: var TBSon; fieldname: cstring): TBSon
retrieves the value belonging to fieldname. Raises EInvalidKey if the attribute does not exist.
proc getId*(obj: var TBSon): TOid
retrieves the _id attribute of obj.
proc insertID*(db: var TDbConn; namespace: string; data: PJsonNode): TOid
converts data to BSON format and inserts it in namespace. Returns the generated OID for the _id field.
proc insert*(db: var TDbConn; namespace: string; data: PJsonNode)
converts data to BSON format and inserts it in namespace.
proc update*(db: var TDbConn; namespace: string; obj: var TBSon)
updates obj in namespace.
proc update*(db: var TDbConn; namespace: string; oid: TOid; obj: PJsonNode)
updates the data with oid to have the new data obj.
proc delete*(db: var TDbConn; namespace: string; oid: TOid)
Deletes the object belonging to oid.
proc delete*(db: var TDbConn; namespace: string; obj: var TBSon)
Deletes the object obj.

Iterators

iterator find*(db: var TDbConn; namespace: string): var TBSon
iterates over any object in namespace.
iterator find*(db: var TDbConn; namespace: string; query, fields: var TBSon): var TBSon
yields the fields of any document that suffices query.
iterator find*(db: var TDbConn; namespace: string; query: var TBSon; 
               fields: varargs[string]): var TBSon
yields the fields of any document that suffices query. If fields is [] the whole document is yielded.
iterator find*(db: var TDbConn; namespace: string; query: string; 
               fields: varargs[string]): var TBSon
yields the fields of any document that suffices query. If fields is [] the whole document is yielded.
Generated: 2012-09-23 21:47:54 UTC