saveRec {Proc4}R Documentation

Saves a P4 Message object to a Mongo database

Description

This function saves an S4 object as a record in a Mongo databalse. It uses as.json to covert the object to a JSON string.

Usage

saveRec(mess, col, serialize=TRUE)

Arguments

mess

The message (object) to be saved.

col

A mongo collection object, produced with a call to mongo().

serialize

A logical flag. If true, serializeJSON is used to protect the data field (and other objects which might contain complex R code.

Value

Returns the message argument, which may be modified by setting the "_id" field if this is the first time saving the object.

Author(s)

Russell Almond

See Also

as.json, P4Message, parseMessage, getOneRec, mongo

Examples


## Not run: ## Need to set up database or code won't run.
m1 <- P4Message("Fred","Task1","PP","Task Done",
                details=list("Selection"="B"))
m2 <- P4Message("Fred","Task1","EI","New Obs",
                details=list("isCorrect"=TRUE,"Selection"="B"))
m3 <- P4Message("Fred","Task1","EA","New Stats",
                details=list("score"=1,"theta"=0.12345,"noitems"=1))

testcol <- mongo("Messages",
                 url="mongodb://test:secret@127.0.0.1:27017/test")
## Mongodb is the protocol
## user=test, password =secret
## Host = 127.0.0.1 -- localhost
## Port = 27017 -- Mongo default
## db = test
## collection = Messages

## Save them back to capture the ID.
m1 <- saveRec(m1,testcol)
m2 <- saveRec(m2,testcol)
m3 <- saveRec(m3,testcol)




## End(Not run)

[Package Proc4 version 0.4-6 Index]