2017-08-05 87 views
0

我主持我的mLab.comMongo數據庫多個集合如下圖所示的畫面:如何顯示我的MongoDB屬性?

enter image description here

我似乎無法能夠訪問「請求」的集合。這是我做了什麼:

首先,我連接到數據庫,並創造了主要工序中的功能(main.js):

mongoose.connect('url', { useMongoClient: true }); 

ipcMain.on('load-requests', function(event) { 
    return Requests.find({}, { sort: {createdAt: -1}}); 
}); 

內部調用schema.js另一個文件我有以下幾點:

var mongoose  = require('mongoose'); 
var Schema  = mongoose.Schema; 

var hosSchema = new Schema({ 
    hospital: String, 
    state: String, 
    reasons: String, 
    requestedDateTime: String, 
    requestNumber: String, 
    status: String, 
}); 

module.exports = mongoose.model('Requests', hosSchema); 

在渲染處理(homePage.html),我有以下:

<div id="page-inner"> 
      <div class="row"> 
       <div class="col-md-4 col-sm-4"> 
        <div class="card teal"> 
         <div class="card-content white-text"> 
          <span class="card-title">state</span> 
          <p>reason</p> 
         </div> 
         <div class="card-action"> 
          <a href="#">requestNumber</a> 
          <a href="#">requestedDateTime</a> 
         </div> 
         </div> 
       </div> 
      </div> 
     </div> 

我想通過id訪問page-inner,並在數據庫中將屬性更改爲相關的一次。例如,應該使用主進程中的函數檢索的屬性(load-requests)更改狀態。

如何顯示homePage.html中的屬性?

回答

1

在Schema.js:

var hosSchemaModel = mongoose.model('Requests', hosSchema); 
module.exports = hosSchemaModel; 

在main.js:

var hosSchemaModel = require("./Schema.js"); 
var getHosSchemas = function() { 
    hosSchemaModel.find({}, function (err, hosSchema) { 
      if (err) { 
      //... 
      } else { 
      //Do something with the hosSchema 
     } 
    }); 
} 
+0

感謝,怎麼樣的渲染過程?我如何訪問「請求」的屬性? –