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

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

问题描述

我正在关注望远镜教程.

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

     $ 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将哪个集合作为子集推送到客户端?

我想对本地主机开发使用同一个数据库(由MongoHQ远程托管),以及实际的实时dev.mysite.com,因此,当我部署到该开发站点时,我在数据库中所做的一切都是也在那里,准备出发.

解决方案

假设您的用户名是username,密码是PASSWORD,数据库是test,主机名是hatch.mongohq.com:

通过外壳连接

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

通过流星连接

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


其他说明

  1. 您应该在client目录之外定义Meteor集合,以便它们可以在客户端和服务器上使用.有关更多详细信息,请参见. /p>

  2. 您会发现连接到远程数据库比本地连接要慢得多,因此通常不建议开发.

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


初始化数据库

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

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

I'm following the telescope tutorial.

  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
    

How can I:

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

So that I can:

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

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?

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.

解决方案

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

Connecting via the shell

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

Connecting via Meteor

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


Other notes

  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.

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

  3. 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.


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天全站免登陆