MongoDB安装流程:
1.在该网站上下载MongoDB软件包:
-url:http://dl.mongodb.org/dl/win32/x86_64
-版本(3.4/3.6安装有问题):win32/mongodb-win32-x86_64-v3.4-latest-signed.msi
2.安装时自定义安装路径(路径不要有中文字符)
3.在安装路径下有一个bin文件,将此路径写入环境变量path
4.在控制台cmd中输入mongo -version,不报错表明路径配置成功
5.在bin文件夹下创建data-db文件夹,在cmd输入:mongod -dbpath D:\MongoDB\data\db
-在浏览器中输入:localhost:27017/出现:It looks like you are trying to access MongoDB over HTTP on the native driver port.
表明此步骤成功
6.在D:\MongoDB\data\db创建文件夹logs\mongo.log
7.以管理员身份进入cmd-进入D:\MongoDB\bin下-输入:
mongod -bind_ip 0.0.0.0 -logpath D:\MongoDB\data\logs\mongo.log -logappend -dbpath D:\MongoDB\data\db -port 27017 -serviceName "MongoDB" -serviceDisplayName "MongoDB" -install
8.在计算机-右键点击'管理'-'服务和应用程序'中查看
9.下载mongodb可视化界面:roboMongodb

启动mongoDB:
D:\database\MongoDB\bin> mongod --dbpath D:\database\MongoDB\data\db[代码启动]
我的电脑(管理)-服务和应用程序-服务(双击)-开启MongoDB[手动启动]

开启MongoDB服务:
-进入MongoDB安装的bin目录下,调出CMD;
-输入mongod --dbpath D:\database\MongoDB\data\db[创建的db文件夹路径]
成功开启的标志:在浏览器中输入localhost:27017(刷新)出现以下一组文字
[It looks like you are trying to access MongoDB over HTTP on the native driver port.]

python环境下的MongoDB存储
1.连接MongoDB:
import pymongo
client=pymongo.MongoClient(host='localhost',port=27017)
2.指定数据库:
db=client['db_name']
3.指定集合:
collection=db['collection_namme']
4.插入数据:insert_one(插入一条数据)/insert_many(插入多条数据)
data={'id':'1001','name':'qinlan','age':20}
collection.insert_one(data)[插入数据]
result=collection.insert_one(data)[pymongo.results.InsertOneResult object at 0x000001F461BD5A48]
print(result.inserted_id)[每插入一条数据,数据库会分配一个id给该记录]

a1={'id':'001','name':'liming','age':25}
a2={'id':'002','name':'mayun'}
result=collection.insert_many([a1,a2])[多条记录以列表形式存放]
print(inserted_ids)
5.查询记录:find_one(查询一条记录)/find(返回一个生成器对象)
result=collection.find_one({'name':'liming'})
print(type(result),result)[字典类型,记录结果]

result=collection.find()
for item in result:
print(item)

补充:
collection.find({'item_name':{'$lt':num}})[item_name属性值小于num]
collection.find({'item_name':{'$gt':num}})[item_name属性值大于num]
collection.find({'item_name':{'$gte':num}})[item_name属性值大于等于num]
collection.find({'item_name':{'$lte':num}})[item_name属性值小于等于num]
collection.find({'item_name':{'$in':[min,max]}})[item_name属性值在范围内]

collection.find({'item_name':{'$regex':'pattern'}})[进行正则匹配查询]
collection.find({'item_name':{'$exists':True}})[查询属性item_name存在的记录]
6.计数(查询记录结果):
collection.find().count()/collection.find({}).count()

7.限制记录数:
collection.find({}).limit(num)

8.更新数据:
condition={'name':'liming'}
item=collection.find_one(condition)[查询记录]
item['age']=50[修改属性值]
collection.update(condition,item)[实现更新]

9.删除数据:
result=collection.delete_one({'attr':value})[删除一条记录]
print(result.deleted_count)

result=collection.delete_many({'attr':{...}})[删除多条记录]
print(result.deleted_count)

result=collection.remove({'attr':value})
print(result.deleted_count)