2017-08-05 26 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

感谢,怎么样的渲染过程?我如何访问“请求”的属性? –