The MongoDB instance of ASP.

Source: Internet
Author: User
Tags mongoclient tojson

Record the required code first, and add the article later.

1      Public classMongonearby2     {3         Private Static ObjectObjlock =New Object();4         Private Staticmongodatabase MONGO;5 6         Private Staticmongodatabase Instance7         {8             Get9             {Ten                 if(MONGO = =NULL) One                 { A                     Lock(Objlock)//Prevent multithreaded Construction -                     { -                         stringConnctionstring ="mongodb://192.168.1.x:27017"; theMongoclient client =Newmongoclient (connctionstring); -Mongoserver Server =client. Getserver (); -MONGO = server. Getdatabase ("nearby");//Database -                     } +                 } -                 returnMONGO; +             } A         } at  -         /// <summary> -         ///Save Record -         /// </summary> -         /// <param name= "info" ></param> -         /// <returns></returns> in          Public Static BOOLSavenearby (nearinfo info) -         { to             if(Info = =NULL) +                 return false; -             Try the             { *Mongocollection collection = Instance.getcollection<nearinfo> ("UserInfo"); $querydocument query =Newquerydocument ();Panax NotoginsengQuery. ADD ("userid", Info.userid); - collection. Remove (query); the  +Writeconcernresult result =collection. Insert (info); AClog.writelog ("Write:"+info. ToJson ()); the                 returnresult. Ok; +             } -             Catch(Exception ex) $             { $Clog.writelog (ex. Message+info. ToJson ()); -                 return false; -             } the         } - Wuyi         /// <summary> the         ///Nearby Users -         /// </summary> Wu         /// <param name= "Sex" ></param> -         /// <param name= "longitude" ></param> About         /// <param name= "latitude" ></param> $         /// <param name= "Total" ></param> -         /// <param name= "Limit" ></param> -         /// <param name= "MaxDistance" ></param> -         /// <returns></returns> A          Public StaticList<userinfo> Getnearbyuser (intmyUID,intSexDoubleLongitude,DoubleLatituderef intTotalintLimit = +,intMaxDistance = -* +) +         { thelist<userinfo> list =NULL; -             Try $             { theList =NewList<userinfo>(); the                 DoubleRadius =6378000; theMongocollection<nearinfo> collection = Instance.getcollection<nearinfo> ("UserInfo"); the  -                 #regionMethod 2 calculates the distance inImongoquery query = Query.ne ("userid", myUID); the                 if(Sex = =0|| Sex = =1) { theQuery =query.and (query.ne ("Sex",1-sex), Query.ne ("userid", myUID)); About                 } theGeonearoptionsbuilder options = geonearoptions.setmaxdistance (MaxDistance *1.0/radius). Setspherical (true). Setdistancemultiplier (RADIUS); the                 varresult =collection. Geonear (query, longitude, latitude, limit, options); the  +                 varResponse =result. Response; -                 foreach(varIteminchresponse["Results"]. Asbsonarray) the                 {BayiBsondocument Bson =item. asbsondocument; the                     vardis = bson["Dis"]. asdouble;//distance from the interval the                     varobj = bson["obj"]. asbsondocument; -Nearinfo info = bsonserializer.deserialize<nearinfo>(obj); -                     if(Info = =NULL) the                         Continue; the  theUserInfo tmp =NewUserInfo { theUserID =Info.userid, -dis =Dis, theUnick =Cuser.getusernick (Info.userid), theHeadimg =cuser.userheadimg (Info.userid). Facemiddle, theUsign = Getmemo (Info.userid), sex= (Info.sex = =1?"male":"female")94                     }; the list. ADD (TMP); thetotal++; the                     //Clog.writelog (info.sex.ToString ());98                 } AboutClog.writelog (myuid+"Read:"+result. Response.tojson ()); -                 #endregion101                 //Clog.writelog (list. ToJson ());102             }103             Catch(Exception ex) {104 Clog.writelog (ex. Message); the             }106             returnlist;107         }108 109          Public Static stringGetmemo (intuserid) the         {111             stringMemo =string. Empty; the             string_tmp =string. Empty;113             int_TMP1 =0; theCuser.getuserdetail (UserID, out_TMP1, out_tmp, out_TMP1, out_tmp, out_tmp, outmemo); the             returnMemo; the         }117}

Blog Park just started to use, do not know how to keep the file ...

The MongoDB instance of ASP.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.