I would like to access Meteor's MongoDB from a Python client, while Meteor is running.
我想从Python客户端访问流星的MongoDB,而流星正在运行。
I can't start a mongod because Meteor's database is locked.
我不能启动单神,因为流星的数据库被锁定了。
How do I access the database from another client?
如何从另一个客户机访问数据库?
6 个解决方案
#1
67
The meteor
command provides a clean way. To get the URL for the running mongod:
流星命令提供了一种干净的方式。要获取运行的mongod的URL:
meteor mongo -U
which you can parse from python.
可以从python中解析。
#2
37
Meteor starts the mongod for you on port 3002 when you run the meteor
command, and stores the mongo data file in .meteor/local/db
当您运行流星命令时,流星在3002端口为您启动mongod,并将mongo数据文件存储在.流星/local/db中
Output from ps aux | grep 'mongod'
shows the mongod command that meteor uses:
输出ps aux | grep 'mongod'显示流星使用的mongod命令:
/usr/local/meteor/mongodb/bin/mongod --bind_ip 127.0.0.1 --smallfiles --port 3002 --dbpath /path/to/your/project/.meteor/local/db
So just connect your mongo client accordingly. In python:
因此,只需相应地连接您的mongo客户端。在python中:
>>> import pymongo
>>> con = pymongo.Connection(host='127.0.0.1', port=3002)
>>> con.database_names()
[u'meteor', u'local']
UPDATE: unfortunately making changes directly in mongo in this way won't reflect live in the app, but the changes will be reflected on a full page (re)load.
更新:不幸的是,以这种方式在mongo中直接进行更改不能在应用程序中实时反映,但是更改将在整个页面加载中反映出来。
#3
6
Use the Meteor deployment instructions
使用流星部署说明
The command will look like this:
命令将如下所示:
PORT=3000 MONGO_URL=mongodb://localhost:27017/myapp node bundle/main.js
#4
2
You can also find it from within server side code using:
您也可以在服务器端代码中找到它,使用:
process.env.MONGO_URL
Even if you don't set this environment variable when running, it gets set to the default. This seems to be how it is found internally (packages/mongo/remote_collection_driver.js)
即使您在运行时不设置这个环境变量,它也会被设置为默认值。内部似乎就是这样找到它的(包/mongo/remote_collection_driver.js)
The one is given by meteor mongo -U
seems to reconstruct the default domain/ip and db-name, but use the port stored in the file.
一个是由流星mongo -U提供的,它似乎重构了默认的域/ip和db-name,但是使用了文件中存储的端口。
You can put this anywhere in the server folder, and read it from the command line.
您可以将它放在服务器文件夹的任何位置,并从命令行读取它。
console.log('db url: ' + process.env.MONGO_URL);
I set up a webpage to display it to double check in the selenium tests that we are using the test database, and not overwriting live data.
我设置了一个页面来显示它,以便在使用测试数据库的selenium测试中再次检查它,而不是覆盖实时数据。
#5
0
And here a shell script to get Mongo URI and Mongo Database:
这里是获取Mongo URI和Mongo数据库的shell脚本:
#!/bin/bash -eux
read -s -p "Enter Password: " password
cmd=$(meteor mongo --url myapp.meteor.com << ENDPASS
$password
ENDPASS)
mongo_uri=$(echo $cmd | cut -f2 -d" ")
mongo_db=$(echo $mongo_uri | cut -d/ -f 4)
#my_client_command_with MONGODB_URI=$mongo_uri MONGO_DB=$mongo_db
````
' ' ' '
#6
-1
In regards to a 10 second delay on updates: Tail the MongoDB oplog! There's more information on how to do it here:
关于10秒的延迟更新:跟踪MongoDB oplog!这里有更多关于如何做到这一点的信息:
http://meteorhacks.com/lets-scale-meteor.html
http://meteorhacks.com/lets-scale-meteor.html
Make sure you install smart collections and use those (instantiate your collections using Meteor.SmartCollection instead of Meteor.Collection) and you will find the updates are essentially immediate.
确保您安装了智能集合并使用它们(使用流星实例化您的集合)。你会发现更新基本上是即时的。
#1
67
The meteor
command provides a clean way. To get the URL for the running mongod:
流星命令提供了一种干净的方式。要获取运行的mongod的URL:
meteor mongo -U
which you can parse from python.
可以从python中解析。
#2
37
Meteor starts the mongod for you on port 3002 when you run the meteor
command, and stores the mongo data file in .meteor/local/db
当您运行流星命令时,流星在3002端口为您启动mongod,并将mongo数据文件存储在.流星/local/db中
Output from ps aux | grep 'mongod'
shows the mongod command that meteor uses:
输出ps aux | grep 'mongod'显示流星使用的mongod命令:
/usr/local/meteor/mongodb/bin/mongod --bind_ip 127.0.0.1 --smallfiles --port 3002 --dbpath /path/to/your/project/.meteor/local/db
So just connect your mongo client accordingly. In python:
因此,只需相应地连接您的mongo客户端。在python中:
>>> import pymongo
>>> con = pymongo.Connection(host='127.0.0.1', port=3002)
>>> con.database_names()
[u'meteor', u'local']
UPDATE: unfortunately making changes directly in mongo in this way won't reflect live in the app, but the changes will be reflected on a full page (re)load.
更新:不幸的是,以这种方式在mongo中直接进行更改不能在应用程序中实时反映,但是更改将在整个页面加载中反映出来。
#3
6
Use the Meteor deployment instructions
使用流星部署说明
The command will look like this:
命令将如下所示:
PORT=3000 MONGO_URL=mongodb://localhost:27017/myapp node bundle/main.js
#4
2
You can also find it from within server side code using:
您也可以在服务器端代码中找到它,使用:
process.env.MONGO_URL
Even if you don't set this environment variable when running, it gets set to the default. This seems to be how it is found internally (packages/mongo/remote_collection_driver.js)
即使您在运行时不设置这个环境变量,它也会被设置为默认值。内部似乎就是这样找到它的(包/mongo/remote_collection_driver.js)
The one is given by meteor mongo -U
seems to reconstruct the default domain/ip and db-name, but use the port stored in the file.
一个是由流星mongo -U提供的,它似乎重构了默认的域/ip和db-name,但是使用了文件中存储的端口。
You can put this anywhere in the server folder, and read it from the command line.
您可以将它放在服务器文件夹的任何位置,并从命令行读取它。
console.log('db url: ' + process.env.MONGO_URL);
I set up a webpage to display it to double check in the selenium tests that we are using the test database, and not overwriting live data.
我设置了一个页面来显示它,以便在使用测试数据库的selenium测试中再次检查它,而不是覆盖实时数据。
#5
0
And here a shell script to get Mongo URI and Mongo Database:
这里是获取Mongo URI和Mongo数据库的shell脚本:
#!/bin/bash -eux
read -s -p "Enter Password: " password
cmd=$(meteor mongo --url myapp.meteor.com << ENDPASS
$password
ENDPASS)
mongo_uri=$(echo $cmd | cut -f2 -d" ")
mongo_db=$(echo $mongo_uri | cut -d/ -f 4)
#my_client_command_with MONGODB_URI=$mongo_uri MONGO_DB=$mongo_db
````
' ' ' '
#6
-1
In regards to a 10 second delay on updates: Tail the MongoDB oplog! There's more information on how to do it here:
关于10秒的延迟更新:跟踪MongoDB oplog!这里有更多关于如何做到这一点的信息:
http://meteorhacks.com/lets-scale-meteor.html
http://meteorhacks.com/lets-scale-meteor.html
Make sure you install smart collections and use those (instantiate your collections using Meteor.SmartCollection instead of Meteor.Collection) and you will find the updates are essentially immediate.
确保您安装了智能集合并使用它们(使用流星实例化您的集合)。你会发现更新基本上是即时的。