tomsu
tomsu

Reputation: 375

Using mongo db in R

I am trying to write R script in which I have to do some operations on mongo database. Therefore, I have a few questions:

  1. How to use double condition? I know how to use single condtion

    mongoDB$find(query = '{"id" : { "$in" : ["1","2"]}}')

    mongoDB$find(query = '{"date" : { "$in" : "2019-08-09"}}')

    How should I connect both conditions in one query? How to write such code?

  2. How to use parameter in mongo code? In my script I will have vector with dynamic number of IDs. How I should write query? I am looking for something like:

    VectorWithIDs <- c(1:1000)

    mongoDB$find(query = '{"id" : { "$in" : VectorWithIDs}}')

Any Ideas how to solve both problems? Thanks in advance!

Upvotes: 1

Views: 133

Answers (1)

davcli
davcli

Reputation: 121

Just do the query with a "," as a separation token.

For example:

mongoDB$find(query = '{"id" : { "$in" : ["1","2"]}, '': "date" : { "$in" : "2019-08-09"}}'}')

Upvotes: 1

Related Questions