mongo.get.last.err: Retrieve an server error code from a mongo connection object

Description Usage Arguments Value See Also Examples

View source: R/mongo_err.R

Description

Retrieve an server error record from a the MongoDB server. This describes the last error that occurs while accessing the give database. While this function retrieves an error record in the form of a mongo.bson record, it also sets the values returned by mongo.get.server.err() and mongo.get.server.err.string(). You may find it more convenient using those after calling mongo.get.last.err() rather than unpacking the returned mongo.bson object.

Usage

1

Arguments

mongo

(mongo) a mongo connection object.

db

(string) The name of the database for which to get the error status.

Value

NULL if no error was reported; otherwise,

(mongo.bson) This BSON object has the form err : "error message string", code : error code integer

See Also

mongo.get.server.err,
mongo.get.server.err.string,
mongo.get.prev.err
mongo.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {

    # try adding a duplicate record when index doesn't allow this

    db <- "test"
    ns <- "test.people"
    mongo.index.create(mongo, ns, '{"name":1}', mongo.index.unique)

    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "name", "John")
    mongo.bson.buffer.append(buf, "age", 22L)
    b <- mongo.bson.from.buffer(buf)
    mongo.insert(mongo, ns, b);

    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "name", "John")
    mongo.bson.buffer.append(buf, "age", 27L)
    b <- mongo.bson.from.buffer(buf)
    mongo.insert(mongo, ns, b);

    err <- mongo.get.last.err(mongo, db)
    print(mongo.get.server.err(mongo))
    print(mongo.get.server.err.string(mongo))
}

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