【问题标题】:pymongo to RMongo, mongodb sort querypymongo转RMongo,mongodb排序查询
【发布时间】:2017-09-08 16:03:23
【问题描述】:

在 pymongo 中,我正在执行这样的排序查询:

from pymongo import MongoClient
client = MongoClient()
dbase = client[dbname]
collection = dbase[symbol]
start = time.time()
cursor = collection.find().sort([{'_id', -1}]).limit(6000)
data = list(cursor)

现在尝试在 R 中做同样的事情...

library("RMongo")
mongo <- mongoDbConnect("dbname", "localhost", 27017) 
query = '{sort({_id: -1})}'
output <- dbGetQuery(mongo, "symbol", query, skip=0, limit=6000)

> output
data frame with 0 columns and 0 rows

这里正确的 JSON 查询字符串格式是什么?

【问题讨论】:

    标签: mongodb sorting pymongo rmongo


    【解决方案1】:

    用蒙古石想通了……

    library('mongolite')
    con <- mongo("collection_name", url = "mongodb://localhost:27017/dbname")
    output <- con$find('{}', sort='{"_id":-1}', limit=6000)
    

    【讨论】:

      猜你喜欢
      • 2010-12-17
      • 1970-01-01
      • 1970-01-01
      • 2018-11-02
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多