jeroen / mongolite

Fast and Simple MongoDB Client for R
https://jeroen.github.io/mongolite/
284 stars 64 forks source link

Undefined BSON Type 6 for undefined data #208

Closed ralmond closed 4 years ago

ralmond commented 4 years ago

I made an error in a javascript data import routine, which left one field "undefined." When I tried to use col$find(), it generated an error about an undefined BSON type.

I think this should be changed into a warning, and an NA returned for the value. (This would make the problem in the database easier to find).

Here is some javascript code (run in the mongo shell) to generate a problematic collection:

var apps = [{"app":"ecd://epls.coe.fsu.edu/P4test",doc:"Test application"},
                   {"app":"ecd://sample.com/Fred",doc:"Fred's app.}];
db.CreateCollection("Apps");
apps.forEach(function (row) {
  db.Apps.insert({"app":row.app,"appStem":row.appStem,active:true,doc:row.doc});
}

This will create a table that has value "undefined" for appStem. Now in R,

col <- mongo("Apps")
col$find()

What I think should happen here is that this should report a table as usual, with the missing fields set as NAs.

jeroen commented 4 years ago

I guess that makes sense. Can you construct a minimal example that creates such a field (using the js client or what it was that you used), so that I can test the problem?