Windows MongoDB 安装

下载

先获取电脑版本,可知个人电脑64位,64位的MongoDB是不能运行在32位系统上的php

$ wmic os get caption
Caption
Microsoft Windows 7 Professional
$ wmic os get osarchitecture
OSArchitecture
64-bit

连接 https://www.mongodb.com/downl... 或者直接点击 http://oaq0p7t2g.bkt.clouddn.... 下载html

启动

创建配置文件mongo.conflaravel

vi mongo.conf
#数据库路径
dbpath=D:\mongo\data
#日志输出文件路径
logpath=D:\mongo\log\mongodb.log
#错误日志采用追加模式
logappend=true
#启用日志文件,默认启用
journal=true
#这个选项能够过滤掉一些无用的日志信息,若须要调试使用请设置为false
quiet=true
#端口号 默认为27017
port=27017

进入cmd执行文件目录,用管理员身份运行(重要)git

C:\windows\system32>mongod --remove --serviceName "MongoDB"
2018-08-13T17:26:12.069+0800 I CONTROL  [main] Trying to remove Windows service
'MongoDB'
2018-08-13T17:26:12.070+0800 I CONTROL  [main] Service 'MongoDB' removed

C:\windows\system32>mongod --config "D:\mongo\mongo.conf" --install --serviceNam
e "MongoDB"

C:\windows\system32>net start MongoDB
MongoDB 服务正在启动 ..
MongoDB 服务已经启动成功。
C:\windows\system32>mongo
MongoDB shell version v3.4.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.1
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        http://docs.mongodb.org/
Questions? Try the support group
        http://groups.google.com/group/mongodb-user
Server has startup warnings:
2018-08-13T17:26:44.632+0800 I CONTROL  [initandlisten]
2018-08-13T17:26:44.632+0800 I CONTROL  [initandlisten] ** WARNING: Access contr
ol is not enabled for the database.
2018-08-13T17:26:44.632+0800 I CONTROL  [initandlisten] **          Read and wri
te access to data and configuration is unrestricted.
2018-08-13T17:26:44.632+0800 I CONTROL  [initandlisten]
> show dbs
admin  0.000GB
local  0.000GB

任务管理器能够查看到
filegithub

工具

图形化工具 https://adminmongo.markmoffat... https://github.com/mrvautin/a...
Robomongo http://blog.robomongo.org/rob...mongodb

安装PHP MongoDB扩展

由于用到 https://packagist.org/package... 这个包,
去网站http://php.net/manual/en/mong... http://pecl.php.net/package/m... 选择对应版本
http://pecl.php.net/package/m... 我用的PHP7.1 选择 https://windows.php.net/downl... 下载后修改 php.ini
须要注意的是 当你使用 find 时,这个方法会自动把参数转换成 ObjectId https://laravel-china.org/top...
Order::where('id','201805301502401358078994')->first(); 替换 $order=Order::find('201805301502401358078994');shell

参考

https://vxhly.github.io/2017/...
https://segmentfault.com/a/11...
http://wiki.jikexueyuan.com/p...
http://www.runoob.com/mongodb...
https://segmentfault.com/a/11...
升级PHP7操做MongoDB
php mongodb
PHP7之Mongodb的开发详解
入门教程
中文文档数据库