mongodb非关系型数据库

NoSQL数据库的产生就是为了解决大规模数据集合多重数据种类带来的挑战,特别是大数据应用难题。

js吞噬作用Any application that can be written in JavaScript, will eventually be written in JavaScript.
这句话的出处是Jeff Atwood在2007年写的博客《The Principle of Least Power》,Jeff Atwood是Stack Overflow的联合创始人。

安装

1、 官网下载


下一步下一步傻瓜式操作即可
2、简单使用
双击执行mongod.exe

即可在你的电脑上启动一个mongodb服务
双击执行mongo.exe

即可启动一个客户端去链接操作Mongodb数据库

使用

1、建库
use xxxx
2、建表
db.xxx.insert({})
3、增
db.xxx.insert({})

for(var i = 0;i<2;i++){db.user.insert({"age":i})}

4、查
全表查询

db.xxx.find()

条件查询

db.xxx.find({"age":1})

5、删

db.xxx.remove({})//不给条件是全集合删除

6、改

db.xxx.update({},{})//第一个参数是条件对象 ,第二个参数是目标数据

修改mongodb的默认配置

image.png

bin文件夹中修改mongod.cfg文件即可

在egg中使用mongodb

1、链接

//安装egg-mongoose
npm install egg-mongoose -S

plugin.js中开启

mongoose:{
    enable: true,
    package: 'egg-mongoose',
}

config.default.js中配置

 config.mongoose={
    url: prod ? 'mongodb:eggadmin:123456@localhost:27017/bloguser' : 'mongodb://127.0.0.1:27017/bloguser',
    options: {
      useUnifiedTopology: true,
    }
  }

2、准备实体类
app/model
针对user表创建一个实体类
User.js

'use strict';
 
/**
 * @description: Mongoose book Schema,
 */
 
module.exports = app => {
 const mongoose = app.mongoose;
 const Schema = mongoose.Schema;
 const UserSchema = new Schema({
    name: { type: String }, /* 书籍名称 */
 });
 return mongoose.model('user', UserSchema);
};

在代码中使用

this.ctx.model.User.find({
          });
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容