MongoDB在python中的使用
文章目录
MongoDB在python中的使用安装配置文件
客户端Pychar插件Python链接Mongodb基本使用基本概念插入数据ObjectID文档
查询数据统计排序分页更新删除
mongoDB是由C++编写的分布式文档数据库。 内部使用类似于Json的bson格式。 中文手册https://www.w3cschool.cn/mongodb/
安装
https://www.mongodb.com/download-center/communitywindows下载官方zip,解压即可使用。
组件文件名Servermongod.exeRoutermongos.exeClientmongo.exeMonitoringToolsmongostat.exe,mongotop.exeimportExportToolsmongodump.exe,mongorestore.exe,mongoexport.exe,mongoimport.exeMiscellaneousToolsbsondump.exe,mongofiles.exe,mongooplog.exe,mongoperf.exe
运行
$ pwd
/d/Application/mogodb/package/mongodb4.0/bin
gdy@gdy MINGW64 /d/Application/mogodb/package/mongodb4.0/bin
$ ./mongod.exe
2019-08-13T22:01:34.963+0800 I STORAGE [main] Max cache overflow file size custom option: 0
2019-08-13T22:01:35.408+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-08-13T22:01:35.412+0800 I CONTROL [initandlisten] MongoDB starting : pid=20852 port=27017 dbpath=D:\data\db\ 64-bit host=gdy
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] db version v4.0.12
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] git version: 5776e3cbf9e7afe86e6b29e22520ffb6766e95d4
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] allocator: tcmalloc
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] modules: none
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] build environment:
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] distmod: 2008plus-ssl
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] distarch: x86_64
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] target_arch: x86_64
2019-08-13T22:01:35.413+0800 I CONTROL [initandlisten] options: {}
2019-08-13T22:01:35.434+0800 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory D:\data\db\ not found., terminating
2019-08-13T22:01:35.434+0800 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2019-08-13T22:01:35.434+0800 I CONTROL [initandlisten] now exiting
2019-08-13T22:01:35.434+0800 I CONTROL [initandlisten] shutting down with code:100
gdy@gdy MINGW64 /d/Application/mogodb/package/mongodb4.0/bin
$
启动服务出错,原因在于找不到数据目录。windows下创建该目录D:\data\db\选项说明
--bind_ip ip逗号分隔ip地址。默认localhost--bing_ip_all绑定所有本地ip地址--port port端口,默认27017--dbpath path数据路径,缺省为\data\db\。windows下缺省就是当前盘符的根目录--logpath path指定日志文件,替代stdout,说明默认是控制台打印日志-f file指定配置文件,yaml格式注册wiendows服务
–install 注册windwos服务–serviceName name 服务名称–serviceDisplayName name 服务显示名
配置文件
mongodb配置使用YAML格式 嵌套使用缩进晚餐,不支持Tab等制表符,支持空格 冒号后要有空格 Yaml参考https://www.w3cschool.cn/iqmrhf/dotvpozt.html 配置mongoing.com/docs/reference/configuration-options.html 在mongodb安装目录新建配置文件mongodb.yml。内容如下:
systemLog:
destination: file
path: "D:/Application/mogodb/package/mongodb4.0/mongod.log"
logAppend: true
storage:
dbPath: "D:/Applicat