简体   繁体   English

指定多个字段-RMongoDB

[英]Specifying multiple fields - RMongoDB

What is the proper syntax for specify multiple fields to be returned? 指定要返回的多个字段的正确语法是什么?

When one field is specified, I do not have any issues returning results in my cursor: 指定一个字段后,我在游标中返回结果没有任何问题:

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

I have tried multiple alternatives for specifying more than one field, but I can't seem to find the correct syntax. 我尝试了多种方法来指定多个字段,但是我似乎找不到正确的语法。 An example is below: 下面是一个示例:

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

I tried doing the specification in the find statement as well: 我也尝试在find语句中执行规范:

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

This seems to be a simple issue, but I cannot get the results I am looking for. 这似乎是一个简单的问题,但是我无法获得想要的结果。 Any help would be greatly appreciated! 任何帮助将不胜感激!

似乎您需要的是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM