[英]MongoDB C# and how to update from Client Side using javascript
I lovely update a document with values(Maps coord) from clienside (under privileges). 我很高兴用clienside(在特权下)用values(Maps coord)更新文档。 MongoDB use javascript in some internals functions and for MapReduce but is not clear for me if i can use client side scripts to update my repository with values.
MongoDB在某些内部函数和MapReduce中使用javascript,但对我来说不清楚,如果我可以使用客户端脚本用值更新存储库。 I searching to pass values from client side to an updater Db.Repository.Updater(item).
我正在搜索将值从客户端传递到更新程序Db.Repository.Updater(item)。 It's possible to make this using javascript or need a webservice or a rest function.
可以使用javascript进行此操作,或者需要网络服务或rest函数。
Can some expert clarify this point and suggest the way. 可以请一些专家澄清这一点并提出建议。
Many thanks. 非常感谢。
There is http interface in mongodb , so you can send direct update request to mongodb through $.ajax for example, or you can send ajax requests to yours handlers/pages/controllers and use mongo-csharp driver as usual for updates. mongodb中有http接口 ,因此您可以例如通过$ .ajax向mongodb发送直接更新请求,也可以将ajax请求发送给您的处理程序/页面/控制器,并像往常一样使用mongo-csharp驱动程序进行更新。 Make your choise...
让你选择...
Include jquery at page first. 首先在页面上包含jquery。 In 'Update' button click handler paste code like this(to send ajax request):
在“更新”按钮中,单击处理程序粘贴如下代码(以发送ajax请求):
$.ajax({
type: "POST",
url: "SomePage.aspx",
data: "name=John&location=Boston",
success: function(msg){
alert( "Data Saved: " + msg );
}
});
In page(but it seems to me that better to use http hadlers ajax handling): 在页面中(但在我看来,最好使用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)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.