2017-08-09 108 views
0

我想爲Cloudbase和MongoDB使用雲端函數。問題是我不知道如何將我的Mongo數據庫連接到雲功能。我的數據庫部署在matlab中。 我做了這個模式:如何將MongoDB與雲端函數一起用於Firebase?

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

var patientSchema = new Schema({ 

    name: { 
     type: String, 
     required : true, 
    }, 

    disease:{ 
     type: String, 
     required : true, 
    }, 

    medication_provided: { 
     type: String, 
     required : true, 
    }, 

    date : { 
     type : Date, 
    } 
}) 

const patient = mongoose.model('patientInfo', patientSchema) 
module.exports = patient 

然後我要求項目index.js文件架構,並導出了一個名爲getAllPatient功能。

const patient = require('../Patient') 
const functions = require('firebase-functions'); 
const mongoose = require('mongoose') 

mongoose.connect('mongodb://patient:[email protected]:39869/patient',{useMongoClient: true}) 
exports.getAllPatient = functions.https.onRequest((request, response) => { 
    patient.find({}).then((data) => { 
     response.send(data) 
    }) 
}) 

,但給了我一個錯誤,「錯誤:無法處理請求」

+0

你能編輯你的問題,以表明你確切地看到了那個錯誤嗎? –

+0

exports.getAllPatient = functions.https.onRequest((請求,響應)=> { patient.find({})。然後加入((數據)=> { response.send(數據) }) }) –

+0

我沒有問代碼 - 你已經展示過了。您是否在Firebase控制檯,瀏覽器或其他地方看到錯誤? –

回答

相關問題