2

我很喜欢用来自客户端的值(地图坐标)更新一个文档(在特权下)。MongoDB 在一些内部函数和 MapReduce 中使用 javascript,但我不清楚我是否可以使用客户端脚本来使用值更新我的存储库。我搜索将值从客户端传递到更新程序 Db.Repository.Updater(item)。可以使用 javascript 或需要 web 服务或休息功能来做到这一点。

一些专家能否澄清这一点并提出建议。
非常感谢。

4

1 回答 1

1

mongodb 中有http 接口,因此您可以通过 $.ajax向 mongodb 发送直接更新请求,或者您可以将 ajax 请求发送到您的 handlers/pages/controllers 并像往常一样使用 mongo-csharp 驱动程序进行更新。做出你的选择...

首先在页面中包含 jquery。在“更新”按钮中单击处理程序粘贴代码,如下所示(发送 ajax 请求):

$.ajax({
   type: "POST",
   url: "SomePage.aspx",
   data: "name=John&location=Boston",
   success: function(msg){
     alert( "Data Saved: " + msg );
   }
 });

在页面中(但在我看来,使用 http hadlers ajax 处理更好):

public void Page_Load(object sender, EventArgs e)
{
  var name = HttpContext.Current.Request["name"];
  var location = HttpContext.Current.Request["location"];
  var item = new Item(){Name = name, Location = location};
  //here update or insert your item, do what you want
  Db.Repository.Updater(item)
}
于 2011-02-22T22:18:26.477 回答