Previously written about how to access the MongoDB database with R, now write down how to filter the conditions (constraints) to make the call to the data. The actual statement invocation is similar to the MONGO query method.
How to connect to a MONGODB database specific reference I
Test<-mongolite::mongo (collection = "collection", url = "Mongodb://username:[email protected]:27017/database", verbose = FALSE, options = Ssl_options ())
1, # #如果只想要部分列数据, (some corresponding field data) can use this statement
Data_mongo=test$find (Fields = ' {"columnname1": True, "columnname2": True, "columnname2": true} ')
COLUMNNAME1 represents the name of the field you want
2. # #如果想筛选某字段指定值对应的数据可以如下做
Data_mongo2=test$find (' {' name ': ' Lisi ', ' sex ': ' Male '} ')
3, # #如果想限定日期, if the date in MONGO is a date format instead of a string format, you can do the following
Maxtime<-as. POSIXCT (Paste0 (Sys.date (), "00:00:00") # #使用今天的00点, convert to POSIXCT format (time can be modified), or you can use Sys.time () Current time
maxtimes<-As.integer (maxtime) * # #转化成日期的数值类型
Data_mongo <-test$find (' {' {' date1 ': {"$gte": {"$date": {"$numberLong": "', D, '"} }}} '))
For more information, refer to the following website
r-mongodb-accessing MongoDB and fetching data _ii