没有字段名称的mongodb查询结果 [英] mongodb query result without field name

查看:72
本文介绍了没有字段名称的mongodb查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法只用值而不用字段名来获取 mongodb 查询结果.我的查询给了我以下结果:

Is there a way to get mongodb query results with only the values and not the field names. My query gives me the following result:

{
           "t_number" : 2508
},
{
           "t_number" : 2560
},
{
           "t_number" : 2599
}

理想情况下,我希望查询结果为 [2508,2560,2599].或者,如果这不可能,是否可以将查询结果设为 [{2508},{2560},{2599}].我知道我可以迭代结果并更改我的编程语言中的格式.我正在寻找一种方法来从 mongodb 获取它并节省一些工作.

Ideally I want the query result to be [2508,2560,2599]. Or if that is not possible, is it possible to get the query result as [{2508},{2560},{2599}]. I know that I can iterate over the result and change the format in my programming language. I am looking for a way to get that from mongodb and save some work.

推荐答案

不,你不能直接做.

但是这个衬垫可以帮助您:

But this one liner could help you:

db.collection.find({},{_id:0, t_number:1}).toArray().map(function(ele) {return ele.t_number} );

这篇关于没有字段名称的mongodb查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆