【问题标题】:Empty GET Response Using Python Eve API and MongoDB Atlas使用 Python Eve API 和 MongoDB Atlas 的空 GET 响应
【发布时间】:2019-11-29 05:21:12
【问题描述】:

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

MONGO_DBNAME = "Nintendo"
MONGO_URI = "mongodb+srv://user:password@xyz.gcp.mongodb.net/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】:

    我通过pymongo URI parser 发现该URI 试图访问测试数据库,而不是游戏数据库。我相信这发生在Eve relies on Flask-Pymongo 之后。我刚刚将上面的 URI 链接从 "mongodb+srv://user:password@xyz.gcp.mongodb.net/test?retryWrites=true&w=majority" 更改为 "mongodb+srv://user:password@xyz.gcp .mongodb.net/Games?retryWrites=true&w=majority”。现在它起作用了!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-11-06
      • 1970-01-01
      • 2017-06-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多