mongo.create: Create an object of class "mongo"

Description Usage Arguments Details Value See Also Examples

View source: R/mongo.R

Description

Connect to a MongoDB server or replset and return an object of class "mongo" used for further communication over the connection.

Usage

1
2
mongo.create(host = "127.0.0.1", name = "", username = "",
  password = "", db = "admin", timeout = 0L)

Arguments

host

(string vector) A list of hosts/ports to which to connect. If a port is not given, 27017 is used. Seperate ports from the IP address by colon, like "120.0.0.1:12345".

name

(string) The name of the replset to which to connect. If name == "" (the default), the hosts are tried one by one until a connection is made. Otherwise, name must be the name of the replset and the given hosts are assumed to be seeds of the replset. Each of these is connected to and queried in turn until one reports that it is a master. This master is then queried for a list of hosts and these are in turn connected to and verified as belonging to the given replset name. When one of these reports that it is a master, that connection is used to form the actual connection as returned.

username

(string) The username to be used for authentication purposes. The default username of "" indicates that no user authentication is to be performed by the initial connect.

password

(string) The password corresponding to the given username.

db

(string) The name of the database upon which to authenticate the given username and password. If authentication fails, the connection is disconnected, but mongo.get.err() will indicate not indicate an error.

timeout

(as.integer) The number of milliseconds to wait before timing out of a network operation. The default (0L) indicates no timeout.

Details

All parameters are stored as attributes of the returned mongo object. Note that these attributes only reflect the initial parameters. Only the external data pointed to by the "mongo" attribute actually changes if, for example, mongo.timeout is called after the initial call to mongo.create.

Value

If successful, a mongo object for use in subsequent database operations; otherwise, mongo.get.err() may be called on the returned mongo object to see why it failed.

See Also

mongo,
mongo.is.connected,
mongo.disconnect,
mongo.reconnect,
mongo.get.err,
mongo.get.primary,
mongo.get.hosts,
mongo.get.socket,
mongo.set.timeout,
mongo.get.timeout.

Examples

1
2
3
4
mongo <- mongo.create()
## Not run: 
    mongo <- mongo.create("192.168.0.3")
## End(Not run)

jonkatz2/rmongodb documentation built on May 19, 2019, 7:30 p.m.