mongodb 使用 group 查询出错

mongodb 使用 group 查询出错

 

# Issue

最近使用 Mongodb 创建 collection 时,创建名为 project.share.group 的集合时会创建成功,并且代码显示数据已保存到集合,在 shell 中也能够通过 show collections 能够查看到对应集合

https://img2.sycdn.imooc.com/5d2db9960001693f03470278.jpg

 

但是通过 db.project.share.group.find() 命令显示数据时报错,显示TypeError: db.project.share.group.find is not a function

https://img2.sycdn.imooc.com/5d2db99a0001e95107220058.jpg

 

# Solution

通过 db.getCollection("project.share.group").find() 可成功获取
因为 group 在 mongodb 属于保留字段,当出现时 mongodb 会有另外的意义(具体待 Google~)

https://img3.sycdn.imooc.com/5d2db99e0001742907110055.jpg

posted @ 2021-02-02 13:17  da0h1  阅读(300)  评论(0编辑  收藏  举报