Search code examples
rmongodbrmongodb

Error in eval(expr, envir, enclos) when using rmongodbHelper


I'm working with rmongodb and rmongodbHelper packages and i've built this function.

CUPS_CP_TAR36 <- function(codi,cant){
  cups <- vector()
  query <- json_to_bson('{"clLst.U_COD_POSTAL": codi, "clLst.TARIFA_ATR": {"$in": "3.0A","3.1A","6.1"]}}')
  output <- json_to_bson('{"id":1}')
  cursor <- mongo.find(mongo, sips, query, fields=output, limit=cant)
  k = 0
  while(mongo.cursor.next(cursor)){
    k = k + 1
    cups[k] <- mongo.bson.value(mongo.cursor.value(cursor), "_id") 
  }
    return(cups)  
}

but when I try to use it:

example <- CUPS_CP_TAR36(codi="08036", cant=10)

I get the following error and really dont know why, i'm not used to write my own functions:

Error in eval(expr, envir, enclos) : object 'codi' not found

Thanks!


Solution

  • Try latest rmongodb version from github. bson from json works out of the box. Moreover mongo.bson.to.list works fine for every case, so you dont't need to construct bson from json. I have plans to push new version of the package to CRAN next week.

    library(devtools)
    install_github("mongosoup/rmongodb")