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)
})
})
,但给了我一个错误,“错误:无法处理请求”
你能编辑你的问题,以表明你确切地看到了那个错误吗? –
exports.getAllPatient = functions.https.onRequest((请求,响应)=> { patient.find({})。然后加入((数据)=> { response.send(数据) }) }) –
我没有问代码 - 你已经展示过了。您是否在Firebase控制台,浏览器或其他地方看到错误? –