简体   繁体   中英

MongoDB C# and how to update from Client Side using javascript

I lovely update a document with values(Maps coord) from clienside (under privileges). 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. I searching to pass values from client side to an updater Db.Repository.Updater(item). It's possible to make this using javascript or need a webservice or a rest function.

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. Make your choise...

Include jquery at page first. In 'Update' button click handler paste code like this(to send ajax request):

$.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):

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)
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM