MongoDB implementation file deletion

Source: Internet
Author: User
Tags mongodb

MongoDB implementation file deletion

Do Itoo in the process, in the implementation of the MongoDB file deletion when encountering point problems, Internet search, many online resources, want to find out what they want is not easy, so can only try, good mentality, pondering a few days to achieve the deletion of files according to the ID, but today looked at, delete has a place to optimize, is the multi-select Delete, many times prompt deletion success, so the bite-yigujin to solve it, this really want to thank Jiege, helped me a lot of busy AH

This is the core code that the foreground removes:

Deletes the selected file $ ("#btndelete") according to the file ID. Click (function () {///To determine if the file to be deleted is selected var rows = $ ('                  
               #fileList '). DataGrid (' getselected '); if (!rows | | rows = = NULL) {$.messager.alert ("Prompt", "Select the file you want to delete.
                   ");
               Return
               
               } var files = $ (' #fileList '). DataGrid (' Getselections ');

               var obj = eval (files);
               var fileid = ';
                   Intercept Fileid for (var i = 0; i < files.length; i++) {obj[i]._id + = ' | ';
               Fileid + = obj[i]._id;//Get ID} console.log (Fileid); Transfer data, execute the controller's Delete method $.ajax ({type: ' POST ', url: '/mongodbhe Lp/processrequest ', data: {action: ' DELETE ', Value:fileid}, Success:function (DA TA) {
                       GetFiles ();
                   Alert ("Delete file succeeded");
                   }, Error:function (err) {alert (ERR);
      
           }
               }); })


Background code:

<summary>///delete files according to Objectid///</summary>//<returns></re turns> public void Delete () {//Gets the array of the foreground string filesid = Reques
                t["value"]; Intercept array element string[] File = Filesid.
                Split (' | ');
                Remove the last set of ' | ' list<string> fileList = file.
                ToList ();
                Filelist.remove (Filelist[filelist.count-1]);
                Chaku mongogridfssettings fssetting = new Mongogridfssettings () {Root = fileTable};
                Mongogridfs fs = new Mongogridfs (DB, fssetting); Mongocollection collection = DB.
                GetCollection (fileTable + ". Files"); Traverse Delete foreach (string item in fileList) {var result = collection.
                    
                Remove (Query.eq ("_id", New ObjectId (item));                
            }} 


Summarize:

Try more, you need more guts.




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.