taggedMongofind: Find values inside documents, with pointers to the...

Description Usage Arguments Value Examples

View source: R/Mongo_extensions.R

Description

Try to find values in an array in different documents, and list them. You can also add tagfields, useful as pointers to which documents they are coming from. Say, for example, you have a database of scientific articles, each with multiple authors, and you want a list of authors, along with which documents they have produced. This gives back a list of these authors, along with identifier-fields for each document

Usage

1
2
3
4
taggedMongofind(moncol, qry = "{}", tagfields = "_id", arrayfield,
  sort = "{}", skip = 0, limit = 0, handler = NULL, pagesize = 1000,
  cachesize = 50000, verbose = FALSE,
  stringsAsFactors = default.stringsAsFactors())

Arguments

moncol

mongo-collection pointer. This can be obtained with YourMonplusObject$col, or call this function via your monplus-object

qry

Query to run to decide what documents to return. This is on document-level, so if you query "Author": "LastName": "Smith", you'll also get Smiths co-authors. To delete this, you can either subset later, or provide a handler

tagfields

Field(s) to return as identifier labels. These should be top-level values

arrayfield

One field that is an array. This may have multiple subfields, e.g. author having first name and last name. The results are combined into one dataframe along with tagfields. Nested fields are seperated by dots.

sort

Sorting to use, as a JSON object (passed on to Mongo-engine)

skip

number of records to skip. Useful together with limit, to continue later

limit

limit to the number of records returned, or 0 for no limit

handler

handler to further process results. Results are first transformed to a data.frame, then given to the handler, per record.

pagesize

size of page to use when querying mongo-engine

cachesize

size of intermediate cache to use. Set this for debugging purposes, may be removed in the future

verbose

emit extra output (counter)

stringsAsFactors

logical: should character vectors be converted to factors? The ‘factory-fresh’ default is TRUE, but this can be changed by setting options(stringsAsFactors = FALSE).

Value

A dataframe, consisting of the fields in arrayfield, and (repeated) top-level document fields. The top-level fields are prefixed with "rec_"

Examples

1
2
3
4
5
6
7
8
# Assumed: we can establish a connection to mongodb://localhost:27017,
# and that this is a new or empty database/collection
MyMongo <- monPlus('MyCol','MyMon')
MyMongo$insert(c('{"OwnID":"Doc1","Authors": {"Name": ["John Smith", "Ben"], "RegistrNo": [1,2]}}',
'{"OwnID":"Doc2","Authors": {"Name": ["John Smith", "William Smith"], "RegistrNo": [3,4]}}',
'{"OwnID":"Doc3","Authors": {"Name": ["William", "Benjamin Smith"], "RegistrNo": [4,2]}}'))
taggedMongofind(MyMongo$col, '{"Authors.Name": "John Smith"}',
arrayfield = 'Authors', tagfields = 'OwnID')

Dans-labs/MongoPlussed documentation built on July 23, 2018, 2:35 p.m.