【发布时间】:2018-01-17 01:21:09
【问题描述】:
我想为 Firebase 和 MongoDB 使用 Cloud Functions。问题是我不知道如何将我的 Mongo 数据库与 Cloud Functions 连接。我的数据库部署在 matlab 上。 我制作了这个架构:
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:patient123@ds139869.mlab.com:39869/patient',{useMongoClient: true})
exports.getAllPatient = functions.https.onRequest((request, response) => {
patient.find({}).then((data) => {
response.send(data)
})
})
但给我一个错误“错误:无法处理请求”
【问题讨论】:
-
您能否编辑您的问题以指明您在哪里看到该错误?
-
exports.getAllPatient = functions.https.onRequest((request, response) => { patient.find({}).then((data) => { response.send(data) }) })
-
我不是在问代码 - 你已经展示过了。您是否在 Firebase 控制台、浏览器或其他地方看到错误?
-
只是出于好奇@DougStevenson 是不是因为他无法发出出站请求而出现错误?
-
这可能是问题所在,但这不是我希望看到的错误消息。
标签: mongodb firebase mongoose google-cloud-functions