简体   繁体   English

MongoDB C#以及如何使用JavaScript从客户端更新

[英]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.

相关问题 如何使用javascript从客户端获取c#timezoneinfo类的客户端时区ID - How to get the client timezone id for c# timezoneinfo class from client side using javascript 如何使用JavaScript / jQuery在客户端从MongoDB获取数据 - How to get data from MongoDB on client side using javascript/jQuery 如何在客户端(使用javascript)和服务器端验证mac地址和ipaddress(使用c#) - How to Validate mac address & ipaddress in client side(using javascript) & server side(using c#) 流星从客户端更新mongodb - Meteor update mongodb from client side 从C#将数据集传递到客户端JavaScript - Passing dataset to client side javascript from c# 使用JavaScript在客户端访问MongoDB - Acessing MongoDB on the Client-Side using JavaScript 如何通过 JavaScript 从服务器端的 Z2567A5EC9705EB7AC2C98403 - How can I call client side C# program function via JavaScript from web page on server side? 使用来自客户端的 MongoDB 和 Javascript - Using MongoDB from client with Javascript 如何从客户端的mongodb获取数据? - How to get data from mongodb on client side? 如何使用客户端的HTML5 / Javascript和控制器的C#代码将MVC中的录制视频作为blob发布/上传? - How to post/upload recorded video as blob in MVC using HTML5/ Javascript at client side and C# code at controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM