search

Home  >  Q&A  >  body text

redis - 如一简单博客数据库,NoSQL该如何设计?

这几天看NoSQL,还是不太理解从传统的关系型数据库中的表、行、列转换到NoSQL。

比如一个最简单的博客数据库设计,有分类表,有文章表、每个分类对应N条文章。

这样的传统关系数据库设计怎么转变到Mongodb、Redis呢?

巴扎黑巴扎黑2767 days ago795

reply all(6)I'll reply

  • PHPz

    PHPz2017-04-22 09:00:54

    Having used Mongodb, I designed it like this, for the article:

    • Title
    • Publish time
    • ...
    • Category
    • Tags (using array type)

    Query articles by tags and categories, you can use aggregation Map/Reduce, etc.

    For Redis, processing these is mainly implemented in your own application.

    reply
    0
  • PHP中文网

    PHP中文网2017-04-22 09:00:54

    Just use files for blogs. Put them in folders by date and name the folders with dates. Tags also use folders, and put softlinks of article files in them

    reply
    0
  • 迷茫

    迷茫2017-04-22 09:00:54

    SQL name | MongoDB name

    database | database
    table | collection
    row | document/BSON document
    column | field
    index | index
    table | joins
    primary key | primary key


    Example: Create a table

    Use SQL statements

    CREATE TABLE users (
        id MEDIUMINT NOT NULL
            AUTO_INCREMENT,
        user_id Varchar(30),
        age Number,
        status char(1),
        PRIMARY KEY (id)
    )
    

    Use NoSQL statements

    db.users.insert( {
        user_id: "abc123",
        age: 55,
        status: "A"
     } )
    

    reply
    0
  • PHP中文网

    PHP中文网2017-04-22 09:00:54

    You can completely use the idea of ​​​​relational database to design the database, such as:

    category collection:

    name:string 
    

    posts collection:

    category_id: object_id
    title:string 
    

    You can also nest sub-documents, there are many posts doc under category collection

    category:

    posts: []
    

    reply
    0
  • PHPz

    PHPz2017-04-22 09:00:54

    To use NoSQL database, you must first abandon the idea of ​​relational database. Use an object-based approach to handle data structures. Each NoSQL database represents a different design idea for object processing. This problem is too big. To learn NoSQL, forget about relational databases first.

    reply
    0
  • PHPz

    PHPz2017-04-22 09:00:54

    Many people have answered, but I haven’t seen a more comprehensive answer

    reply
    0
  • Cancelreply