2017-04-12 77 views
1

在pymongo我正在做一個排序的查詢是這樣的:pymongo到RMongo,MongoDB的排序查詢

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查詢字符串格式在這裏?

回答

0

想通了與mongolite ....

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