On mongo database

mongodb (non-relational database: data collection and document storage)

Sequence of operations

1. Open the database server

    Mongod --dbpath  e:data2(新建的自定义路径)

2, the client opens (not servers, open at the root of the installation mongoose)

3、mongo

4, there are several users view

    show dbs

5, using a database (if the user does not create a database)

    use + 数据库

6, insert data

    db.表名.insert({"":""})

7, view the current collection

    show collections

8, view the current contents of the collection

    db.当前集合名.find()

9, a plurality of data inserted

    for(var i=0;i<10;i++){
        db.数据库名.insert({"name":"stu"+i,"age":"10+i"})
    }

10, query data

    (lt(小于),gt(大于),gte(大于等于),lte(小于等于))

. 11, db collection name .find ({ 'fields': {key: value}})

    找到年龄大于15的数据
    db.集合名.find({'age':{$gte:15}})

12, remove a piece of data

    db.集合名.remove(条件)

13, the query $ or (or table)

    db.集合名.find({$or:[{字符:值},{字符:值}]})

14, the query (and represented)

    db.集合名.find({"age":{$gt:15,$lt:18}})

15, modify (update)

    db.集合名.update({"name":"stu"},{$set:{key:value}})

16, ascending and descending

    db.集合名.find().sort({age:-1}) -1表示降序
    db.集合名.find().sort({age:1}) 1表示升序

17, delete the current collection

    db.集合名.drop()

18, password encryption (one-way encryption and two-way encryption)

1、什么是加密?
        crypto 模块提供了加密功能,包括对 OpenSSL 的哈希、HMAC、加密、解密、签名、以及验证功能的一整套封装。
2、如何实现?
        const crypto = require('crypto')
        const secret = 'abcdefg';
        const hash = crypto.createHmac('sha256', secret)
                        .update('I love cupcakes')
                        .digest('hex');
        console.log(hash);
        打印:c0fa1bc00531bd78ef38c628449c5102aeabd49b5dc3a2a516ea6ea959d6658e

Guess you like

Origin www.cnblogs.com/cc0419/p/12110967.html