mongo.insert: Add record to a collection

Description Usage Arguments Details Value See Also Examples

View source: R/mongo_records.R

Description

Add record to a collection.

Usage

1

Arguments

mongo

(mongo) a mongo connection object.

ns

(string) namespace of the collection to which to add the record.

b

(mongo.bson) The record to add.

In addition, b may be a list which will be converted to a mongo.bson object by mongo.bson.from.list().

Details

See http://www.mongodb.org/display/DOCS/Inserting.

Value

TRUE if the command was successfully sent to the server; otherwise, FALSE.

mongo.get.last.err() may be examined to verify that the insert was successful on the server if necessary.

See Also

mongo.insert.batch,
mongo.update,
mongo.find,
mongo.find.one,
mongo.remove,
mongo.bson,
mongo.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    ns <- "test.people"

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

    # do the same thing in shorthand:
    mongo.insert(mongo, ns, list(name="Joe", age=22L))
}

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