我有以下数据库
{"userName":"John Smith", "followers":8075,"body":"my text 1","confirmed":"no"}
{"userName":"james Bond", "followers":819, "body":"my text 2", "confirmed":"yes"}
{"userName":"Julia Roberts","followers":3882,"body":"my text 3","confirmed":"yes"}
{"userName":"Jamal David","followers":6531, "body":"my text 4","confirmed":"yes"}
{"userName":"jane fonda","followers":3941, "body":"my text 5","confirmed":"no"}
我需要计算名称以Ja开头的关注者数量(不区分大小写)
这就是我想要做的事情:
db.test.find({$and:[{followers:{$gte:0}}, {"userName":{$regex :/^Ja/i}}]})
但它给了我bach的整个匹配字符串,而我只需要userName。你能帮帮我吗?
答案 0 :(得分:1)
将projection添加到查询
db.test.find({followers:{$gte:0}, userName:{$regex :/^Ja/i}}, {_id:0, userName:1})
请记住:
_id:0
,否则