14.3Class MongoDB

Create a client connection to a MongoDB database.

Class MongoDB( [host],[port] )
host default to localhost.
port default to 27017.
Methods
addUserAdds a user to the DB.
authenticateAuthenticates a user on the DB.
commandRun a command on a database
connectConnect or reconnect to MongoDB server.
countCounts the entities in a collection.
createIndexCreates an index for the given namespace and key.
disconnectDisconnect to MongoDB server.
dropCollectionRemoves a collection from a database.
dropDatabaseDrops the database.
findFinds instances corresponding to the given query.
findOneFinds an instance.
hostWhen given a parameter, change the host for the next connection attempt. Else return the current host.
insertInserts an instance.
isConnectedChecks if the DB is connected.
portWhen given a parameter, change the port for the next connection attempt. Else return the current port.
removeRemoves an instance.
updateUpdates an existing instance.

Methods

addUser

Adds a user to the DB.

MongoDB.addUser( db, user, pass )
db Database
user User ID to be added
pass Password for the new user.
Returntrue if user was added

authenticate

Authenticates a user on the DB.

MongoDB.authenticate( db, user, pass )
db Database
user User ID
pass Password
Returntrue if authenticated

command

Run a command on a database

MongoDB.command( db, cmd )
db Database
cmd BSON instance
ReturnBSON result or nil

connect

Connect or reconnect to MongoDB server.

MongoDB.connect()

count

Counts the entities in a collection.

MongoDB.count( db, coll, [query] )
db Database
coll Collection to be queried.
query BSON instance
ReturnTotal count or -1 on error

createIndex

Creates an index for the given namespace and key.

MongoDB.createIndex( ns, key, [unique],[drop_dups] )
ns namespace
key BSON instance
unique (boolean) default false
drop_dups (boolean) default false
ReturnBSON result or nil

disconnect

Disconnect to MongoDB server.

MongoDB.disconnect()

dropCollection

Removes a collection from a database.

MongoDB.dropCollection( db, coll )
db The database
coll The collection to be dropped
Returntrue on success

dropDatabase

Drops the database.

MongoDB.dropDatabase( db )
db The database to be dropped
Returntrue on success

find

Finds instances corresponding to the given query.

MongoDB.find( ns, [query],[fields],[skip],[limit] )
ns Namespace
query BSON instance
fields BSON instance
skip default 0
limit default 0 (all)
ReturnAn array of BSON results or nil

findOne

Finds an instance.

MongoDB.findOne( ns, [query] )
ns namespace
query BSON instance
ReturnBSON result or nil

host

When given a parameter, change the host for the next connection attempt. Else return the current host.

MongoDB.host( [host] )
host
Returnself (with param) or the current host.

insert

Inserts an instance.

MongoDB.insert( ns, bson )
ns namespace
bson BSONObj instance, or an array of BSON instances
Returntrue on success

isConnected

Checks if the DB is connected.

MongoDB.isConnected()
Returntrue if connected

port

When given a parameter, change the port for the next connection attempt. Else return the current port.

MongoDB.port( [port] )
port
Returnself (with param) or the current port.

remove

Removes an instance.

MongoDB.remove( ns, cond )
ns namespace
cond BSON instance (conditions)
Returntrue on success

update

Updates an existing instance.

MongoDB.update( ns, cond, op, [upsert],[multiple] )
ns namespace
cond BSON instance (conditions)
op BSON instance (operations)
upsert (boolean) default true
multiple (boolean) default true
Returntrue on success
Made with http://www.falconpl.org