使用“meteor mongo"在本地主机上但使用远程数据库 [英] Using "meteor mongo" on localhost but with remote Database

查看:15
本文介绍了使用“meteor mongo"在本地主机上但使用远程数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习望远镜教程.

I'm following the telescope tutorial.

  1. 我创建了一个/client/collections/myfile.js
  2. 我在本地主机上,但我正在使用托管在 MongoHQ 上的远程数据库启动 Meteor,而不是使用 Meteor 的本地数据库.
  3. 在本教程中,我被告知通过打开 Mongo 控制台插入新帖子.

  1. I created a /client/collections/myfile.js
  2. I'm on localhost, but I'm launching Meteor with remote DB hosted on MongoHQ instead of using Meteor's local DB.
  3. In this tutorial I'm told to insert a new post by opening the Mongo console.

 $ meteor mongo

我该怎么做:

$ meteor mongo (somehow connect to my remote DB to use the meteor commands in terminal

这样我就可以:

$ db.collectionname.insert({ stuff });

或者在这种情况下这与Meteor"无关,而我只是在 Meteor 之外使用 Mongo shell?我在/client/collections/collection.js"中创建的集合只是为了告诉 Meteor 将哪个集合作为子集推送给客户端?

Or does this have nothing to do with "Meteor" in this case and I just use a Mongo shell outside of Meteor? The collection that I created in "/client/collections/collection.js" is this simply for telling Meteor which collection to push as a subset to the client?

我想对我的本地主机开发和我的实际实时 dev.mysite.com 使用相同的数据库(通过 MongoHQ 远程托管),所以当我部署到这个开发站点时,我在数据库中所做的任何事情都是也在那里准备出发.

I'd like to use the same DB ( remotely hosted with MongoHQ) for my localhost development, and my actual live dev.mysite.com so when I deploy to this dev site, anything I've done in the DB is also there and ready to go.

推荐答案

假设你有一个用户名username,密码PASSWORD,一个名为的数据库testhatch.mongohq.com 的主机名:

Assuming you had a username of username, a password of PASSWORD, a database named test, and a hostname of hatch.mongohq.com:

$ mongo hatch.mongohq.com:27017/test -u username -p PASSWORD

通过 Meteor 连接

$ MONGO_URL="mongodb://username:PASSWORD@hatch.mongohq.com:27017/test" meteor

<小时>

其他注意事项

  1. 您应该在 client 目录之外定义 Meteor 集合,以便它们可以在客户端和服务器上使用.请参阅了解更多详情.

  1. You should define your Meteor collections outside of the client directory so they can be used on both the client and the server. See this for more details.

你会发现连接远程数据库比本地连接慢很多,所以一般不推荐用于开发.

You will find that connecting to a remote database is much slower than connecting locally, so it's generally not recommended for development.

Meteor 在启动时为您创建一个开发数据库.这也为您提供了非常有用的命令:meteor resetmeteor mongo,用于重置并连接到所述数据库.

Meteor creates a dev database for you when it starts. This also affords you the very helpful commands: meteor reset and meteor mongo, to reset, and connect to said database.

<小时>

初始化您的数据库

在服务器上创建一个文件进行初始化 - 例如server/initialize.js.当服务器启动时,您可以添加尚不存在的用户或其他文档.例如:


Initializing your database

Create a file on the server for initialization - e.g. server/initialize.js. When the server starts you can add users or other documents which do not yet exist. For example:

Meteor.startup(function() {
  if (Meteor.users.find().count() === 0) {
    Accounts.createUser({
      username: 'jsmith',
      password: 'password',
      profile: {
        firstName: 'John',
        lastName: 'Smith'
      }
    });
  }
});

这篇关于使用“meteor mongo"在本地主机上但使用远程数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆