0

I am trying to use the $in command from the mongolite package in R:

list1 = ["430885","903587","565811","966761","963697","682921","565810","287862","951363"]

I am trying to put the following list into the find query.

sample3 <- data.frame(list(my_collection2$find('{"MatchId" : {"$in" : list1}}')))

So far i am always getting this error.

Error: Invalid JSON object: {"MatchId" : {"$in" : list1}}
Drenmi
  • 8,492
  • 4
  • 42
  • 51
  • 3
    Escape your dollar-sign, since in regexes it has special meaning: `\\$`. (I'm inferring likely packages you're using here, since `...$find(...)` is not base R. Please be explicit about non-base packages and other related source. That is not an R `list` or json, that looks like `python` or some other language.) – r2evans Dec 27 '18 at 05:18
  • 1
    There are other possible issues with your code. If you need more help, I suggest you make this question *reproducible*. This includes sample code (including listing non-base R packages), sample data (e.g., a json-complete string), and your expected output. Refs: https://stackoverflow.com/questions/5963269, https://stackoverflow.com/help/mcve, and https://stackoverflow.com/tags/r/info. – r2evans Dec 27 '18 at 05:21
  • The non-base r package i am using is mongolite. Sample data cannot be shown properly as i am using the mongodb connection. list1 <- list("951371","1034827","1041615","533291","584929") i also tried to convert to json using toJSON from rjson package So far two errors come for the code most of the time. Error: Invalid JSON object: {"MatchId" : { "$in" : list1 } } or Error in "$in":list1 : NA/NaN argument In addition: Warning messages: 1: In "$in":list1 : numerical expression has 5 elements: only the first used 2: In bson_or_json(query) : NAs introduced by coercion – Thomas Varghese Dec 27 '18 at 05:42
  • Please include non-base packages (and relevant code, if any more) in the question, not in a comment. Your question references JSON but you never show any, so I suggest you either give us sample valid JSON that reproduces your problem, or completely fashion a `list` object that has the same properties. Otherwise there is no way to reproduce your bug and less likelihood of you getting a resolution. (Because you reference converting *to* json ... I'm confused what you are trying to do. What is your source? Your expected output? What code causes the error??) – r2evans Dec 27 '18 at 05:47
  • Try building an R `list` and then convert it to JSON when calling `find`. For instance: `x<-list(MatchId=list("$in"=list1))` and then `...$find(fromJSON(x))`. – nicola Dec 27 '18 at 06:19

0 Answers0