使用Python Eve API和MongoDB Atlas的空GET响应

问题描述 投票:0回答:1

我目前正在使用MongoDB Atlas,并且在尝试在云上进行测试之前,我试图查看是否可以通过Eve在本地访问数据。我在settings.py中有以下内容:

MONGO_DBNAME = "Nintendo"
MONGO_URI = "mongodb+srv://user:[email protected]/test?retryWrites=true&w=majority"

Games = {
    'schema': {
        "Name": {'type': 'string'},
        "Year": {'type': 'number'}
    }
}


DOMAIN = {
    "Games": Games
}

而且我在“游戏”集合下有以下演示数据:

{"Name":"Legend of Zelda: Breath of the Wild","Year":2017}
{"Name":"Luigi's Mansion","Year":2001}

[当我使用http://localhost:1234/Games查询演示数据时,我希望有两个文档,但没有匹配的文档。具体来说,我得到以下响应:

<resource href="Games" title="Games">
   <link rel="parent" href="/" title="home"/>
   <_meta>
      <max_results>25</max_results>
      <page>1</page>
      <total>0</total>
   </_meta>
</resource>

我已经通过使用PyMongo驱动程序连接到MongoDB Atlas来检查URI是否正确,并且我还检查了DB和Collection名称是否正确。知道这种情况下发生了什么吗?谢谢!

mongodb eve
1个回答
0
投票

我通过pymongo URI parser知道URI试图访问测试数据库而不是游戏数据库。我相信自Eve relies on Flask-Pymongo起便会发生这种情况。我刚刚将上面的URI链接从“ mongodb + srv:// user:[email protected]/test?retryWrites = true&w = majority”更改为“ mongodb + srv:// user:[email protected]” .mongodb.net / Games?retryWrites = true&w = majority“。现在就可以了!

© www.soinside.com 2019 - 2024. All rights reserved.