【问题标题】:Specifying multiple fields - RMongoDB指定多个字段 - RMongoDB
【发布时间】:2014-02-27 21:17:19
【问题描述】:

指定要返回的多个字段的正确语法是什么?

当指定一个字段时,我在光标中返回结果没有任何问题:

#Field specifications
fields <- mongo.bson.from.list(list(text = 1L))

我尝试了多种替代方法来指定多个字段,但似乎找不到正确的语法。下面是一个例子:

#Field specifications
fields <- mongo.bson.from.list(list(_id = 0L, text = 1L, name = 1L))

我也尝试在 find 语句中进行规范:

cursor <- mongo.find(mongo, "twitter.test", query, 
                     fields = list(_id = 0L, text = 1L, name = 1L), 
                     sort = count_sort, 
                     limit = 1L)

这似乎是一个简单的问题,但我无法得到我正在寻找的结果。任何帮助将不胜感激!

【问题讨论】:

标签: r mongodb rmongodb


【解决方案1】:

看来你只需要:

fields <- mongo.bson.from.list(c(list(_id = 0L), list(text = 1L), list(name = 1L)))

【讨论】:

    猜你喜欢
    • 2011-02-08
    • 2013-01-06
    • 2012-10-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多