linux 建立网站,wordpress如何删除你好和设置菜单,平台网站怎么做seo,做企业网站建设公司哪家好MongoDB MongoDB简介体系结构Linux系统中的安装启动和连接#xff08;1#xff09;先到官网下载压缩包——解压——重命名新建几个目录#xff0c;分别用来存储数据和日志#xff1a;新建并修改配置文件官网下载MongoDB Compass MongoDB简介
MongoDB是一个开源、高… MongoDB MongoDB简介体系结构Linux系统中的安装启动和连接1先到官网下载压缩包——解压——重命名新建几个目录分别用来存储数据和日志新建并修改配置文件官网下载MongoDB Compass MongoDB简介
MongoDB是一个开源、高性能、无模式的文档型数据库当初的设计就是用于简化开发和方便扩展是NoSQL数据库产品中的一种。是最 像关系型数据库MySQL的非关系型数据库。它支持的数据结构非常松散是一种类似于 JSON 的 格式叫BSON所以它既可以存储比较复杂的数据类型又相当的灵活。MongoDB中的记录是一个文档它是一个由字段和值对field:value组成的数据结构。MongoDB文档类似于JSON对象即一个文档认为就是一个对象。字段的数据类型是字符型它的值除了使用基本的一些类型外还可以包括其他文档、普通数组和文档数组。
体系结构 Linux系统中的安装启动和连接
目标在Linux中部署一个单机的MongoDB作为生产环境下使用。 步骤如下
1先到官网下载压缩包——解压——重命名
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-6.0.8.tgz
tar -zxvf mongodb-linux-x86_64-rhel70-6.0.8.tgz
mv mongodb-linux-x86_64-rhel70-6.0.8 mongodb从soft文件夹移动到usr/local下
mv /soft/mongodb /usr/local/新建几个目录分别用来存储数据和日志
#数据存储目录
mkdir -p /usr/local/mongodb/data/db
#日志存储目录
mkdir -p /usr/local/mongodb/single/log新建并修改配置文件
vi /mongodb/single/mongod.conf配置文件的内容如下
systemLog:#MongoDB发送所有日志输出的目标指定为文件# #The path of the log file to which mongod or mongos should send all diagnostic logging informationdestination: file#mongod或mongos应向其发送所有诊断日志记录信息的日志文件的路径path: /usr/local/mongodb/log/mongod.log#当mongos或mongod实例重新启动时mongos或mongod会将新条目附加到现有日志文件的末尾。logAppend: true
storage:#mongod实例存储其数据的目录。storage.dbPath设置仅适用于mongod。##The directory where the mongod instance stores its data.Default Value is /data/db.dbPath: /usr/local/mongodb/data/dbjournal:#启用或禁用持久性日志以确保数据文件保持有效和可恢复。enabled: true
processManagement:#启用在后台运行mongos或mongod进程的守护进程模式。fork: true
net:#服务实例绑定的IP默认是localhostbindIp: localhost,192.168.0.2#bindIp#绑定的端口默认是27017port: 27017启动MongoDB服务
/usr/local/mongodb/bin/mongod -f /usr/local/mongodb/mongod.conf官网下载MongoDB Compass db.flyComment.insertMany([
{_id:1,articleid:100001,content:我们不应该把清晨浪费在手机上健康很重要一杯温水幸福你我他。,userid:1002,nickname:相忘于江湖,createdatetime:new Date(2019-08-05T22:08:15.522Z),likenum:NumberInt(1000),state:1}
,{_id:2,articleid:100001,content:我夏天空腹喝凉开水冬天喝温开水,userid:1005,nickname:伊人憔悴,createdatetime:new Date(2019-08-05T23:58:51.485Z),likenum:NumberInt(888),state:1}
,{_id:3,articleid:100001,content:我一直喝凉开水冬天夏天都喝。,userid:1004,nickname:杰克船长,createdatetime:new Date(2019-08-06T01:05:06.321Z),likenum:NumberInt(666),state:1},
{_id:4,articleid:100001,content:专家说不能空腹吃饭影响健康。,userid:1003,nickname:凯撒,createdatetime:new Date(2019-08-06T08:18:35.288Z),likenum:NumberInt(2000),state:1},
{_id:5,articleid:100001,content:研究表明刚烧开的水千万不能喝因为烫嘴。,userid:1003,nickname:凯撒,createdatetime:new Date(2019-08-06T11:01:02.521Z),likenum:NumberInt(3000),state:1}]);db.flyComment.find({articleid:100001})
db.flyComment.find({articleid:100001},{articleid:1,nickname:1})db.flyComment.updateOne({_id:1},{$set:{likenum:NumberInt(1002)}})
db.flyComment.updateMany({_id:1},{$set:{articleid:10002,likenum:NumberInt(1014)}})db.flyComment.findOneAndDelete({_id:1})db.flyComment.find().limit(2)
db.flyComment.find().limit(2).skip(2)
db.flyComment.find({},{userid:1}).sort({userid:1})
db.flyComment.find({},{userid:1}).sort({userid:-1})
#模糊查询
db.flyComment.find({content:/开水/})
# 大于1000
db.flyComment.find({likenum:{$gt:NumberInt(1000)}})
#in
db.flyComment.find({userid:{$in:[1003,1004]}})
# not in
db.flyComment.find({userid:{$nin:[1003,1004]}})
#and
db.flyComment.find({$and:[{likenum:{$gte:NumberInt(700)}},{likenum:{$lt:NumberInt(2000)}}]})
#or
db.flyComment.find({$or:[ {userid:1003} ,{likenum:{$lt:1000} }]})
#count
db.flyComment.countDocuments({likenum:{$lt:1000}})