使用JSON / HTTP / REST接口查询MongoDB [英] Querying MongoDB with JSON / HTTP / REST Interface

查看:752
本文介绍了使用JSON / HTTP / REST接口查询MongoDB的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在构建一个ASP.Net Web应用程序,并希望从MongoDB(远程托管)访问数据。我的任何文档看起来像这样(在Utc字段上确保索引);

  {
_id:{ $ oid:509501393e8785025c10bc21},
索引:1,
Url:http:...,
CameraId:123,
Utc:{$ date:1351955858006}
}

考虑到用户端,我想以最大速度获取这些数据。我尝试过的一个选项是在Page.aspx上通过JSON调用本地Web服务,它使用MongoDB C#驱动程序在两个日期(Utc)之间查询文档。这样做,但似乎使用Web服务在请求/响应周期中添加了一些额外的毫秒(在平均1.3秒内提供了使用db.foo.findOne()的单个文档的请求)。我们的问题是:



该项目的平均文件数量是50,000,这将增加到30,000,000。我正确的说,使用Web服务在请求/响应周期中添加了一些延迟
(毫秒)? (因为MongoDB实际上是
需要几毫秒来完成查询)
  • 第二个选项是使用MongoDB的 HTTP / REST界面。这样我可以避免Web服务并直接查询MongoDB。这里
    i需要您的意见,


    • 有没有办法在两个使用HTTP / REST的日期之间查询MongoDB?

    • 有没有办法用'>'和'<'条件使用HTTP / REST查询MongoDB?

    • 看起来如何直接在Page.aspx上访问数据库有安全性的观点?


  • 上述模式的任何其他查询替代或优化?

  • 我的相关问题是这里



    问候。

    解决方案>

    MongoDB的本机HTTP接口不是用于查询的。你应该继续做你正在做的事情。此外,您的MongoDB服务器不应为了安全目的而公开公开,您应该按照目前的方式执行中间层。


    I am building an ASP.Net web application and want to access data from MongoDB (remotely hosted). Any of my documents looks like this (have ensured index on Utc field);

    { 
       "_id" : { "$oid" : "509501393e8785025c10bc21" }, 
       "Index" : 1,
       "Url" : "http:...", 
       "CameraId" : 123,  
       "Utc" : { "$date" : 1351955858006 } 
    }
    

    Considering the performance on user end, I want to fetch this data at max speed. One option that i have tried is calling a local Web Service via JSON on Page.aspx which uses MongoDB C# driver to query documents between two Dates (Utc). That works but seems like using web service adds some extra milliseconds in request/response cycle (request for single document using db.foo.findOne() is served in 1.3 seconds on average). Average number of documents in that collection is 50,000 which will increase up-to 30,00,000.

    My questions are:

    1. Am i right in saying that using web services adds some delay (millisecs) in request/response cycle ? (because MongoDB actually takes few milliseconds to complete the query)
    2. Second Option is to use MongoDB's HTTP / REST Interface. That way i might avoid web services and directly query MongoDB. Here i need your opinion on,
      • Is there a way to query MongoDB between two Dates using HTTP/REST ?,
      • Is there a way to query MongoDB with '>' and '<' conditions using HTTP/REST ?,
      • How does it seem, accessing DB directly on Page.aspx with security point of view ?
    3. Any other querying alternative OR optimizations for above schema?

    My related question is here.

    Regards.

    解决方案

    MongoDB's native HTTP interface is not built for querying. You should continue to do what you are doing. In addition, your MongoDB servers should not be exposed publicly for security purposes and you should always go through a middle tier as you are currently doing.

    这篇关于使用JSON / HTTP / REST接口查询MongoDB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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