mongo.insert.batch: Add multiple records to a collection

Description Usage Arguments Details Value See Also Examples

View source: R/mongo_records.R

Description

Add multiple records to a collection. This function eliminates some network traffic and server overhead by sending all the records in a single message.

Usage

1

Arguments

mongo

(mongo) a mongo connection object.

ns

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

lst

A list of (mongo.bson) records to add.

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,
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
14
15
16
17
18
19
20
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    ns <- "test.people"

    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "name", "Dave")
    mongo.bson.buffer.append(buf, "age", 27L)
    x <- mongo.bson.from.buffer(buf)

    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "name", "Fred")
    mongo.bson.buffer.append(buf, "age", 31L)
    y <- mongo.bson.from.buffer(buf)

    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "name", "Silvia")
    mongo.bson.buffer.append(buf, "city", 24L)
    z <- mongo.bson.from.buffer(buf)
    mongo.insert.batch(mongo, ns, list(x, y, z))
}

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