I am new to working with rmongodb. Currently I'm working with some basic queries. Say I have two variables I'm interested in: Job Candidates and their GPA's. Some of their GPA's are blank as in they didn't include them so their bson value is null. The problem is my queries return different length lists then so I have trouble matching candidates to their names. The name query returns a data frame of 153 candidates, and the GPA query returns a data frame of 132... hence I cannot match them.
This is what I had been doing.
### pulling candidate first names and creating a data frame
buf <- mongo.bson.buffer.create()
query <- mongo.bson.from.buffer(buf)
buf <- mongo.bson.buffer.create()
err <- mongo.bson.buffer.append(buf, "data.FNAME", 1)
field <- mongo.bson.from.buffer(buf)
out <- mongo.find(mongo, "dynamite.tdpCandidates", query, fields = field)
res <- NULL
while(mongo.cursor.next(out)){
value <- mongo.cursor.value(out)
Rvalue <- mongo.bson.to.list(value)
res <- rbind(res, Rvalue)
}
test1 <- data.frame(firstName = unlist(res[,2], recursive = TRUE))
test1 <- data.frame(lapply(test1, as.character), stringsAsFactors=FALSE)
Returns 153 first names.
#### pulling candidate education GPA and creating a dataframe from them
buf <- mongo.bson.buffer.create()
query <- mongo.bson.from.buffer(buf)
buf <- mongo.bson.buffer.create()
err <- mongo.bson.buffer.append(buf, "data.EDUCATION.GPA", 1)
field <- mongo.bson.from.buffer(buf)
out <- mongo.find(mongo, "dynamite.tdpCandidates", query, fields = field)
res <- NULL
while(mongo.cursor.next(out)){
value <- mongo.cursor.value(out)
Rvalue <- mongo.bson.to.list(value)
res <- rbind(res, Rvalue)
}
test10 <- data.frame(candGPA = unlist(res[,2], recursive = TRUE))
test10 <- data.frame(lapply(test10, as.character), stringsAsFactors=FALSE)
Returns 132 GPA's..
If there is a better way to do this or just a simple way to query the bson nulls, I would appreciate any suggestions.