我可以从clienside(在特权下)更新带有值(地图坐标)的文档。 MongoDB在一些内部函数和MapReduce中使用javascript,但如果我可以使用客户端脚本用值更新我的存储库,则不清楚。我搜索从客户端传递值到更新程序Db.Repository.Updater(item)。可以使用javascript或需要web服务或休息功能来实现这一点。
有些专家可以澄清这一点并提出建议 非常感谢。
答案 0 :(得分:1)
有http interface in mongodb,因此您可以向mongodb through $.ajax发送直接更新请求,或者您可以向您的处理程序/页面/控制器发送ajax请求,并像往常一样使用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)
}