r-mongodb-accessing MongoDB and fetching data _ii

Source: Internet
Author: User
Tags string format

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.