前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Meteor 开发环境 mongodb 的连接

Meteor 开发环境 mongodb 的连接

作者头像
我与梦想有个约会
发布2023-10-21 14:09:03
3200
发布2023-10-21 14:09:03
举报
文章被收录于专栏:jiajia_dengjiajia_deng

本文主要总结一下在使用 Meteor 开发过程中对 mongodb 数据库的管理。其中包含使用命令行终端(meteor shell)进行管理,还有图形化界面的工具 Robomongo 工具。

预备知识

当使用 meteor 命令启动 meteor 项目后,meteor 会默认使用 3000 端口作为 web 项目的端口,我们可以通过 http://domainName:3000/ 这样的地址来访问我们的网站。而数据库所使用的端口,则是在这个端口基础上 +1,就是 3001 端口。也就是说,如果你指定启动 meteor 项目时使用了其他端口,比如 meteor -p 8000,那么 mongodb 的数据库连接端口就是 8001

使用 meteor shell 进行管理

通过 meteor shell 管理 mongodb 不需要指定端口,你只要在 meteor 项目启动后的项目目录下执行 meteor mongo 就可以连接到数据库了。如下:

代码语言:javascript
复制
myCode:~/Project/microduino$ meteor mongo
MongoDB shell version: 2.6.7
connecting to: 127.0.0.1:3001/meteor
meteor:PRIMARY>

这样就连接到了当前项目的 mongodb 数据库,通过 help 命令可以看到帮助。

代码语言:javascript
复制
meteor:PRIMARY> help
    db.help()                    help on db methods
    db.mycoll.help()             help on collection methods
    sh.help()                    sharding helpers
    rs.help()                    replica set helpers
    help admin                   administrative help
    help connect                 connecting to a db help
    help keys                    key shortcuts
    help misc                    misc things to know
    help mr                      mapreduce

    show dbs                     show database names
    show collections             show collections in current database
    show users                   show users in current database
    show profile                 show most recent system.profile entries with time >= 1ms
    show logs                    show the accessible logger names
    show log [name]              prints out the last segment of log in memory, 'global' is default
    use <db_name>                set current database
    db.foo.find()                list objects in collection foo
    db.foo.find( { a : 1 } )     list objects in foo where a == 1
    it                           result of the last line evaluated; use to further iterate
    DBQuery.shellBatchSize = x   set default number of items to display on shell
    exit                         quit the mongo shell

通过 show dbs 命令可以查看当前的数据库列表。

代码语言:javascript
复制
meteor:PRIMARY> show dbs
admin   (empty)
local   0.063GB
meteor  0.031GB

上面我们看到,有一个名为 meteor 占用 0.031GB 的空间,使用命令 use meteor 选择它,然后使用命令 show collections 查看所有数据库。

代码语言:javascript
复制
meteor:PRIMARY> use meteor
switched to db meteor
meteor:PRIMARY> show collections
Accounts
AnalyticsEvents
Articles
Cards
Cart
Discounts
Orders
Packages
Products
Sessions
Shipping
Shops
Tags
Taxes
Translations
cfs.Images.filerecord
cfs._tempstore.chunks
cfs_gridfs._tempstore.chunks
cfs_gridfs._tempstore.files
friends
meteor_accounts_loginServiceConfiguration
meteor_oauth_pendingCredentials
meteor_oauth_pendingRequestTokens
modules
oldUsers
roles
system.indexes
users

如果要对数据库进行查询,那么此时你就可以使用命令 db.collectionName.find(...); 来操作了。下面我们来介绍图形化界面的 Robomongo。

使用 Robomongo 管理数据库

下载地址:http://robomongo.org/ 安装完成后,配置连接属性,程序刚打开的时候一片空白,我们要手动点右键 Add 一个新的连接。

输入 mongodb 的连接信息,记住这个端口,要根据你项目启动的端口来决定的。

保存后点击 Connect 连接

连接上以后,就可以通过 meteor-

>Collections 看到所有的数据库信息了

如果想执行查询、更新等语句,可以双击一个数据库,再右侧数据列表的上方输入查询语句

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015-12-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 预备知识
  • 使用 meteor shell 进行管理
  • 使用 Robomongo 管理数据库
相关产品与服务
数据库
云数据库为企业提供了完善的关系型数据库、非关系型数据库、分析型数据库和数据库生态工具。您可以通过产品选择和组合搭建,轻松实现高可靠、高可用性、高性能等数据库需求。云数据库服务也可大幅减少您的运维工作量,更专注于业务发展,让企业一站式享受数据上云及分布式架构的技术红利!
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档