mongo.find.all: Find records in a collection and returns one R data frame...

Description Usage Arguments Details Value See Also Examples

View source: R/mongo_find.R

Description

Find records in a collection that match a given query and return an R data frame object.

Usage

1
2
3
4
mongo.find.all(mongo, ns, query = mongo.bson.empty(),
  sort = mongo.bson.empty(), fields = mongo.bson.empty(), limit = 0L,
  skip = 0L, options = 0L, data.frame = FALSE,
  mongo.oid2character = TRUE, ...)

Arguments

mongo

(mongo) a mongo connection object.

ns

(string) namespace of the collection from which to find records.

query

(mongo.bson) The criteria with which to match the records to be found. The default of mongo.bson.empty() will cause the the very first record in the collection to be returned.

Alternately, query may be a list which will be converted to a mongo.bson object by mongo.bson.from.list().

Alternately, query may be a valid JSON character string which will be converted to a mongo.bson object by mongo.bson.from.JSON().

sort

(mongo.bson) The desired fields by which to sort the returned records. The default of mongo.bson.empty() indicates that no special sorting is to be done; the records will come back in the order that indexes locate them.

Alternately, sort may be a list which will be converted to a mongo.bson object by mongo.bson.from.list().

Alternately, sort may be a valid JSON character string which will be converted to a mongo.bson object by mongo.bson.from.JSON().

fields

(mongo.bson) The desired fields which are to be returned from the matching record. The default of mongo.bson.empty() will cause all fields of the matching record to be returned; however, specific fields may be specified to cut down on network traffic and memory overhead.

Alternately, fields may be a list which will be converted to a mongo.bson object by mongo.bson.from.list().

Alternately, fields may be a valid JSON character string which will be converted to a mongo.bson object by mongo.bson.from.JSON().

limit

(as.integer) The maximum number of records to be returned. A limit of 0L will return all matching records not skipped.

skip

(as.integer) The number of matching records to skip before returning subsequent matching records.

options

(integer vector) Flags governing the requested operation as follows:

  • mongo.find.cursor.tailable

  • mongo.find.slave.ok

  • mongo.find.oplog.replay

  • mongo.find.no.cursor.timeout

  • mongo.find.await.data

  • mongo.find.exhaust

  • mongo.find.partial.results

data.frame

(boolean) If TRUE the result will be an data.frame object, if FALSE it will be an list object. Due to NoSQL in mongodb in most cases a data.frame object will not work!

mongo.oid2character

(boolean) If TRUE monogo_oids will be converted to characters.

...

optional arguments to as.data.frame

Details

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

Value

An R data frame object.

See Also

mongo.find.one,
mongo.insert,
mongo.index.create,
mongo.update,
mongo.remove,
mongo.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
mongo <- mongo.create()
if (mongo.is.connected(mongo)) {
    buf <- mongo.bson.buffer.create()
    mongo.bson.buffer.append(buf, "age", 22L)
    query <- mongo.bson.from.buffer(buf)

    # Find the first 100 records
    #    in collection people of database test where age == 22
    mongo.find.all(mongo, "test.people", query, limit=100L)


    # shorthand: find all records where age=22, sorted by name,
    # and only return the name & address fields:
    mongo.find.all(mongo, "test.people", list(age=22),
                         list(name=1L), list(name=1L, address=1L))
}

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