数据存储-MongoDB
MongoDB安装
非关系型数据库,是一个基于分布式文件存储的开源数据库系统,其内容存储形式类似 JSON 对象,它的字段值可以包含其他文档、数组及文档数组
安装与启动
安装教程:https://zhuanlan.zhihu.com/p/596465307
下载地址:https://www.mongodb.com/try/download/community
使用文档:https://www.mongodb.org.cn/tutorial/55.html
使用教程2:
MongoDB:6.0.3
Mongosh: 1.6.2
win7
MongoDB 3.4.24
安装教程:https://blog.csdn.net/qq_27093465/article/details/54574948
mongod --config D:\LenovoSoftstore\mongo\mongo.conf --install --serviceName "MongoDB"
启动
net start MongoDB #启动 需管理员权限(服务端)
net stop MongoDB #关闭数据库
mongosh # 启动客户端 6.0.3
mongo # 启动客户端 3.4.24
#创建用户
#使用用户权限
exit() #退出
show dbs # 查看数据库
use Mydata #创建并进入数据库
db.Mydata.insert({"name":"google"}) #数据库插入数据
db.Mydata.find()
db.dropDatabase() #进入数据库后 删除
# 集合操作
show collections # 查看集合
db.createCollection("MyCollection") # 创建MyCollectionj集合
db.MyCollection.insert({'username':'jenny','age':20,'gender':300}); #向集合中插入一些数据
db.MyCollection.find() #查询集合内数据
db.MyCollection.drop() #删除集合
# MongoBulkWriteError: db already exists with different case already have: BulkWriteResult 暂未找到解决方法
MongoDB简单使用
# 数据
db.MyCollection.insert({
'id':1,'name':'apple','age':20,'gender':true});
db.MyCollection.insert({
'id':2,'name':'banana','age':20,'gender':false});
db.MyCollection.insert({
'id':3,'name':'city','age':16,'gender':false});
db.MyCollection.insert({
'id':4,'name':'delay','age':20,'gender':true});
db.MyCollection.insert({
'id':5,'name':'effect','age':17,'gender':true});
db.MyCollection.insert({
'id':6,'name':'finite','age':20,'gender':true});
db.MyCollection.insert({
'id':7,'name':'guess','age':10,'gender':true});
# 增
db.MyCollection.insert({
'username':'jenny','age':20,'gender':300});
dict_data = {
'id':1,
'name':'jenny',
'age':55,
'gender':true
}
db.MyCollection.insert(dict_data)
# 删
db.MyCollection.remove({
'username':'jenny'}) #无效方法
db.MyCollection.deleteOne({
'username':'zhangyu'}) #删一个
db.MyCollection.deleteMany({
'gender':true}) #删多个
db.MyCollection.remove({
}) #删所有数据
# 改
db.MyCollection.update(

6818

被折叠的 条评论
为什么被折叠?



