當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript GridFSBucket.delete方法代碼示例

本文整理匯總了TypeScript中mongodb.GridFSBucket.delete方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript GridFSBucket.delete方法的具體用法?TypeScript GridFSBucket.delete怎麽用?TypeScript GridFSBucket.delete使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在mongodb.GridFSBucket的用法示例。


在下文中一共展示了GridFSBucket.delete方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: GridFSBucket

 .then(client => {
   const bucket = new GridFSBucket(client.db());
   bucket.delete(filename, err => {
     if (err) return void reject(err);
     resolve();
   });
 })
開發者ID:zaidka,項目名稱:genieacs,代碼行數:7,代碼來源:db.ts

示例2: getBody

  request.addListener("end", () => {
    const body = getBody();
    const urlParts = url.parse(request.url, true);
    if (PRESETS_REGEX.test(urlParts.pathname)) {
      const presetName = querystring.unescape(
        PRESETS_REGEX.exec(urlParts.pathname)[1]
      );
      if (request.method === "PUT") {
        const preset = JSON.parse(body.toString());
        preset._id = presetName;
        db.presetsCollection.replaceOne(
          { _id: presetName },
          preset,
          { upsert: true },
          err => {
            if (err) return void throwError(err, response);

            cache.del("presets_hash", err => {
              if (err) return void throwError(err, response);

              response.writeHead(200);
              response.end();
            });
          }
        );
      } else if (request.method === "DELETE") {
        db.presetsCollection.deleteOne({ _id: presetName }, err => {
          if (err) return void throwError(err, response);

          cache.del("presets_hash", err => {
            if (err) return void throwError(err, response);

            response.writeHead(200);
            response.end();
          });
        });
      } else {
        response.writeHead(405, { Allow: "PUT, DELETE" });
        response.end("405 Method Not Allowed");
      }
    } else if (OBJECTS_REGEX.test(urlParts.pathname)) {
      const objectName = querystring.unescape(
        OBJECTS_REGEX.exec(urlParts.pathname)[1]
      );
      if (request.method === "PUT") {
        const object = JSON.parse(body.toString());
        object._id = objectName;
        db.objectsCollection.replaceOne(
          { _id: objectName },
          object,
          { upsert: true },
          err => {
            if (err) return void throwError(err, response);

            cache.del("presets_hash", err => {
              if (err) return void throwError(err, response);

              response.writeHead(200);
              response.end();
            });
          }
        );
      } else if (request.method === "DELETE") {
        db.objectsCollection.deleteOne({ _id: objectName }, err => {
          if (err) return void throwError(err, response);

          cache.del("presets_hash", err => {
            if (err) return void throwError(err, response);

            response.writeHead(200);
            response.end();
          });
        });
      } else {
        response.writeHead(405, { Allow: "PUT, DELETE" });
        response.end("405 Method Not Allowed");
      }
    } else if (PROVISIONS_REGEX.test(urlParts.pathname)) {
      const provisionName = querystring.unescape(
        PROVISIONS_REGEX.exec(urlParts.pathname)[1]
      );
      if (request.method === "PUT") {
        const object = {
          _id: provisionName,
          script: body.toString()
        };

        try {
          new vm.Script(`"use strict";(function(){\n${object.script}\n})();`);
        } catch (err) {
          response.writeHead(400);
          response.end(`${err.name}: ${err.message}`);
          return;
        }

        db.provisionsCollection.replaceOne(
          { _id: provisionName },
          object,
          { upsert: true },
          err => {
//.........這裏部分代碼省略.........
開發者ID:zaidka,項目名稱:genieacs,代碼行數:101,代碼來源:nbi.ts


注:本文中的mongodb.GridFSBucket.delete方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。