2

I want to use R to load a collection from mongoDB to R, with filter to increase the speed. The filter can be Or condition or IN a R data.

MongoDB collection

Name     Type

A        M

B        P

C        M

D        P

E        O

RFilter

Criteria

M

P
RData <- MongoCollection$find('{"Type" in RFilter$Criteria}', 
fields = '{
    "Name" : true,
    "Type" : true
    }')

I expect the output: RData

Name     Type

A        M

B        P

C        M

D        P
MilanRegmi
  • 499
  • 3
  • 12
VuTran
  • 21
  • 2

1 Answers1

0

If you need to check-in database to check if name or type is P or M try $or in criteria as below:

{$or:[{Name:{$in:["P","M"]}},{Type:{$in:["P","M"]}}]}

The above $or condition will check in DB if the name is "P" or "M" it'll return document else it'll check in type if it values is "P" or "M" else won't return document if both are not matched.

sushant mehta
  • 1,244
  • 1
  • 7
  • 13
  • I could work with $or, but that could only solve the problem with small factor. The real test is I get a list of selection from other source, and I want to apply that filter to mongoDB collection, which like several million lines, to reduce the run time. – VuTran Aug 13 '19 at 06:55