如何将我的meteor应用程序连接到外部的MongoDB?

我有托pipe在heroku中的Node.JS服务器,我想在我的Meteor应用程序中使用相同的Mongo数据库。

这是我的Node.js服务器中的Mongo数据库:

 var mongoose = require('mongoose'); var Schema = mongoose.Schema; var messageSchema = new Schema({ requestNumber: String, requestedDateTime: String, reasons: String, state: String, hospital: String, phone: String, status: {type: String, default: 'Pending'}, latestUpdate: Date, createdAt: {type: Date, default: Date.now} }); module.exports = mongoose.model('Requests', messageSchema); 

这是我在Meteorcollections:

 Requests = new Mongo.Collection("requests"); Requests.attachSchema(new SimpleSchema({ requestNumber: {type: String}, requestedDateTime: {type: String}, reasons: {type: String}, state: {type: String}, hospital: {type: String}, phone: {type: String}, status: {type: String, defaultValue: 'Pending'}, latestUpdate: {type: Date}, createdAt: {type: Date, defaultValue: Date.now} })); Requests.allow({ insert: function(userId, doc){ return true; }, update: function(userId, doc, fields, modifier){ return true; }, remove: function(userId, doc){ return true; } }); 

这里是我如何连接到我的Node.JS数据库里面的Meteor应用程序:

 Meteor.startup(() => { process.env.MONGO_URL = 'mongodb://...'; }); 

当我在meteor mongo/mongo shell尝试db.requests.find().pretty()时,没有任何内容被打印到控制台。

我在这里做错了什么?

我认为这是连接到外部数据库的错误方法。 您的应用程序启动后,您指定了MONGO_URL 此时它已经启动了内部mongo服务器。

您应该从控制台运行meteor应用时指定MONGO_URL

 MONGO_URL="mongodb://..." meteor 

你可以使用一个小sh脚本来做到这一点:

 #!/bin/sh MONGO_URL="mongodb://..." meteor -s <path_to_settings_file> ... <other_parameters>