MongoDB + Express 环境搭建记
Posted yelao
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MongoDB + Express 环境搭建记相关的知识,希望对你有一定的参考价值。
最近项目需要使用 MongoDB,所以不得不搭建 MongoDB 环境,此文记录搭建过程及使用过程中需要了解的问题。
Linux + Windows 混合搭建调试 MongoDB 记录
版本介绍 :
windows : win10 64bit
linux:ubuntu 14.0.4
nodejs:6.11.2
MongoDB: 4.0.9
MongoDB安装
MongoDB下载地址:https://www.mongodb.com/download-center/community
ubuntu安装MongoDB
1. 下载:点击上方链接选择目标
可以直接点击 DownLoad 下载,或者使用上图链接下载
解压提取
将其中内容移动到/usr/local/mongodb
2. 创建用于存储的数据库和日志目录,数据都将存于此地
该路径可配置,配置文件中要相应参数与之对应
mkdir -p /data/db # 默认数据库目录路径,应手动予以创建
mkdir -p /data/logs
3. 配置环境变量
vi ~/.bashrc
在最后一行插入
export PATH=/usr/local/mongodb/bin:$PATH
4. 运行MongoDB 服务
[email protected]:/# mongod
运行结果:
[email protected]:/# mongod 2019-04-29T16:39:28.558+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols ‘none‘ 2019-04-29T16:39:28.660+0800 I CONTROL [initandlisten] MongoDB starting : pid=5793 port=27017 dbpath=/data/db 64-bit host=qizhuang-virtual-machine 2019-04-29T16:39:28.660+0800 I CONTROL [initandlisten] db version v4.0.9 2019-04-29T16:39:28.660+0800 I CONTROL [initandlisten] git version: fc525e2d9b0e4bceff5c2201457e564362909765 2019-04-29T16:39:28.660+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014 2019-04-29T16:39:28.660+0800 I CONTROL [initandlisten] allocator: tcmalloc 2019-04-29T16:39:28.660+0800 I CONTROL [initandlisten] modules: none 2019-04-29T16:39:28.660+0800 I CONTROL [initandlisten] build environment: 2019-04-29T16:39:28.660+0800 I CONTROL [initandlisten] distmod: ubuntu1404 2019-04-29T16:39:28.661+0800 I CONTROL [initandlisten] distarch: x86_64 2019-04-29T16:39:28.661+0800 I CONTROL [initandlisten] target_arch: x86_64 2019-04-29T16:39:28.661+0800 I CONTROL [initandlisten] options: {} 2019-04-29T16:39:28.708+0800 I STORAGE [initandlisten] Detected data files in /data/db created by the ‘wiredTiger‘ storage engine, so setting the active storage engine to ‘wiredTiger‘. 2019-04-29T16:39:28.708+0800 I STORAGE [initandlisten] 2019-04-29T16:39:28.708+0800 I STORAGE [initandlisten] ** WARNING: Using the XFS filesystem is strongly recommended with the WiredTiger storage engine 2019-04-29T16:39:28.708+0800 I STORAGE [initandlisten] ** See http://dochub.mongodb.org/core/prodnotes-filesystem 2019-04-29T16:39:28.714+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=256M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress), 2019-04-29T16:39:40.351+0800 I STORAGE [initandlisten] WiredTiger message [1556527180:351142][5793:0x7f1436e1fa80], txn-recover: Main recovery loop: starting at 3/29056 to 4/256 2019-04-29T16:39:40.667+0800 I STORAGE [initandlisten] WiredTiger message [1556527180:667802][5793:0x7f1436e1fa80], txn-recover: Recovering log 3 through 4 2019-04-29T16:39:40.756+0800 I STORAGE [initandlisten] WiredTiger message [1556527180:756069][5793:0x7f1436e1fa80], txn-recover: Recovering log 4 through 4 2019-04-29T16:39:40.802+0800 I STORAGE [initandlisten] WiredTiger message [1556527180:802393][5793:0x7f1436e1fa80], txn-recover: Set global recovery timestamp: 0 2019-04-29T16:39:40.886+0800 I RECOVERY [initandlisten] WiredTiger recoveryTimestamp. Ts: Timestamp(0, 0) 2019-04-29T16:39:40.977+0800 I CONTROL [initandlisten] 2019-04-29T16:39:40.977+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2019-04-29T16:39:40.977+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2019-04-29T16:39:40.977+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended. 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost. 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server. 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning. 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always‘. 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** We suggest setting it to ‘never‘ 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always‘. 2019-04-29T16:39:40.978+0800 I CONTROL [initandlisten] ** We suggest setting it to ‘never‘ 2019-04-29T16:39:40.979+0800 I CONTROL [initandlisten] 2019-04-29T16:39:41.217+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory ‘/data/db/diagnostic.data‘ 2019-04-29T16:39:41.301+0800 I NETWORK [initandlisten] waiting for connections on port 27017
5. mongo shell
如果你需要进入MongoDB后台管理,你需要先打开mongodb装目录的下的bin目录,然后执行mongo命令文件。
MongoDB Shell是MongoDB自带的交互式javascript shell,用来对MongoDB进行操作和管理的交互式环境。
[email protected]:/# mongo
运行结果:
[email protected]:/# mongo MongoDB shell version v4.0.9 connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb Implicit session: session { "id" : UUID("9eb5b47f-f872-4525-8906-8ea79bacd38b") } MongoDB server version: 4.0.9
> # 此处可以进行一些交互式操作
以上是关于MongoDB + Express 环境搭建记的主要内容,如果未能解决你的问题,请参考以下文章
使用node+express+mongodb实现用户注册登录和验证功能
从无到有,用Nodejs+express+mongodb搭建简易登陆系统