1
我有Node.JS
服务器托管在heroku中,我想在我的Meteor
应用程序中使用相同的Mongo数据库。如何将我的流星应用程序连接到外部MongoDB?
这里是我的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);
这里是我的收藏Meteor
:
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://...';
});
当我在中尝试db.requests.find().pretty()
时,没有任何内容显示在控制台上。
我在这里做错了什么?
感谢。我做了它,它似乎工作,因为我不能使用“meteor mongo”命令,因为它只连接到本地mongo。但我怎样才能确保它连接?我试过“console.log(Requests.find({}))”,但没有任何返回。抱歉花时间。 –
你可以使用'meteor shell'并运行命令,比如'Requests.find()。fetch()' – Styx
我实际上可以在“meteor shell”中看到它,但是在代码里面,Requests.find({}) , 你知道为什么吗? –