Files

2.8 KiB
Raw Permalink Blame History

id, title, challengeType, forumTopicId, dashedName
id title challengeType forumTopicId dashedName
587d7fb6367417b2b2512c06 安裝和設置 Mongoose 2 301540 install-and-set-up-mongoose

--description--

你可以採用下面的任意一種編寫代碼的方式來完成這些挑戰:

完成本項目後,請將一個正常運行的 demo項目演示託管在可以公開訪問的平臺。 然後在 Solution Link 字段中提交它的 URL。

在這個挑戰中,你將建立一個 MongoDB Atlas 數據庫並導入連接到它所需的軟件包。

按照這篇教程在 MongoDB Atlas 創建一個託管數據庫。

--instructions--

mongodb@~3.6.0mongoose@~5.4.0 添加到項目的 package.json 中。 然後,在 myApp.js 文件中請求 mongoose。 創建一個 .env 文件,給它添加一個 MONGO_URI 變量。 變量的值爲你的 MongoDB Atlas 數據庫 URI。 應用單引號或雙引號包裹 URI。請記住環境變量 = 兩邊不能有空格。 例如,MONGO_URI='VALUE'。 完成後,使用下面的代碼來連接數據庫。

mongoose.connect(<Your URI>, { useNewUrlParser: true, useUnifiedTopology: true });

--hints--

“mongodb” 應在 package.json 中作爲依賴項定義。

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/file/package.json').then(
    (data) => {
      var packJson = JSON.parse(data);
      assert.property(packJson.dependencies, 'mongodb');
    },
    (xhr) => {
      throw new Error(xhr.responseText);
    }
  );

“mongoose” 應在 package.json 中作爲依賴項定義。

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/file/package.json').then(
    (data) => {
      var packJson = JSON.parse(data);
      assert.property(packJson.dependencies, 'mongoose');
    },
    (xhr) => {
      throw new Error(xhr.responseText);
    }
  );

應使用 “mongoose” 連接數據庫。

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/is-mongoose-ok').then(
    (data) => {
      assert.isTrue(data.isMongooseOk, 'mongoose is not connected');
    },
    (xhr) => {
      throw new Error(xhr.responseText);
    }
  );

--solutions--

/**
  Backend challenges don't need solutions, 
  because they would need to be tested against a full working project. 
  Please check our contributing guidelines to learn more.
*/