mongo.bson.buffer.append.int: Append an integer field onto a mongo.bson.buffer

Description Usage Arguments Value See Also Examples

View source: R/bson.R

Description

Append an integer or vector of integers onto a mongo.bson.buffer.

Usage

1

Arguments

buf

(mongo.bson.buffer) The buffer object to which to append.

name

(string) The name (key) of the field appended to the buffer.

value

(integer vector) The integer(s) to append to the buffer.

If value has a dims attribute of length > 1, any names or dimnames attribute is ignored and a nested array is appended.
(Use mongo.bson.buffer.append.object() if you want to preserve dimnames).

If value has a names attribute, a subobject is appended and the subfields are given the indicated names.

Otherwise, if more than one element is present in value it must be a vector of integers and the integers are appended as a subarray.

In the last case, the single value must be coerible to an integer.

Value

TRUE if successful; otherwise, FALSE if an error occured appending the data.

See Also

mongo.bson,
mongo.bson.buffer,
mongo.bson.buffer.append.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.int(buf, "age", 23L)
b <- mongo.bson.from.buffer(buf)

# the above produces a BSON object of the form { "age" : 21 }

buf <- mongo.bson.buffer.create()
mongo.bson.buffer.append.int(buf, "ages", c(21L, 19L, 13L))
b <- mongo.bson.from.buffer(buf)

# the above produces a BSON object of the form { "ages" : [21, 19, 13] }

buf <- mongo.bson.buffer.create()
dim <- c(2L, 4L, 8L)
names(dim) <- c("width", "height", "length")
mongo.bson.buffer.append.int(buf, "board", dim)
b <- mongo.bson.from.buffer(buf)

# theabove produces a BSON object of the form:
# { "board" : { "width" : 2, "height" : 4, "length" : 8 } }

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