mongo数据库安装及简单操作

1,mongodb安装

链接:https://pan.baidu.com/s/15KvAFgYqPHyqnGaazpvxBw 
提取码:6dts 
复制这段内容后打开百度网盘手机App,操作更方便哦

另外:centos安装参考 **https://blog.csdn.net/chenyaoo/article/details/83862257**
https://blog.csdn.net/chenyaoo/article/details/83862257
Community版本官网,现在下载了自带链接软件
from pymongo import MongoClient

#建立MongoDB数据库连接
client = MongoClient('localhost',27017)

#连接所需数据库,test为数据库名
db=client.admin

#连接所用集合,也就是我们通常所说的表,test为表名
collection=db.aa

#接下里就可以用collection来完成对数据库表的一些操作


#查找集合中单条数据
print (collection.find_one())

#向集合中插入数据
collection.insert({"name":'Tom',"age":25,"addr":'Cleveland'})

[添加链接描述](https://img-blog.csdnimg.cn/20190331101934312.png?x-oss-process=image/watermark,tymongo数据库安装及简单操作
2,简单查询内嵌方法(正则没查出来,想出两种思路,一是取出相关全部数据在进行字典遍历判断;二是在储存数据字典设计是重要字典放第一层)

from pymongo import MongoClient
import json

#建立MongoDB数据库连接
client = MongoClient('localhost',27017)

#连接所需数据库,test为数据库名
db=client.admin

#连接所用集合,也就是我们通常所说的表,test为表名
collection=db.aa

#接下里就可以用collection来完成对数据库表的一些操作


#查找集合中单条数据
# print (collection.find_one())

#向集合中插入数据
print(collection.find({"id":"4355227567632915"}))
# cursors=collection.find({},{"keyword":"资生堂"})
# cursors=collection.find({},{".keyword":"资生堂"})
cursors=collection.find({},{"_id":0 }) #{"_id":0 }表示排除_id字段
print(cursors[1])
print(type(cursors[1]))
for sss in cursors:    #取内嵌字典,思路先取出全部,然后再操作,字典遍历出key value再判断keyword字段
    # ss=json.dumps(sss)
    # print(ss)
    # print(type(ss))
    # dd=json.loads(ss)
    # print(type(dd))
    for keys,values in sss.items():
        if values["keyword"] == "资生堂":
            print(keys,values)
            # print(keys)

mongo数据库安装及简单操作