zoukankan      html  css  js  c++  java
  • mongdb基础

    相关概念

    在一个数据库软件中可以包含多个数据仓库,在每个数据仓库中可以包含多个数据集合,每个数据集合中可以包含多文档(具体的数据)

    database 数据库,mongoDB数据库软件中可以建立多个数据库
    collection 集合,一组数据的集合,可以理解为JavaScript中的数组
    document 文档,一条具体的数据,可以理解为JavaScript中的对象
    field 字段,文档中的属性名称,可以理解为JavaScript中的对象属性

    使用步骤

    1.引入mongoose模块

    2.创建文章集合规则

    3.根据规则创建集合

    4.将集合规则作为模块成员进行导出

    实例

    //1.引入mongoose模块
    const mongoose = require('mongoose');
    //2.创建文章集合规则
    const articleSchema = new mongoose.Schema({
            title: {
                type: String,
                maxlength: 20,
                minlength: 4,
                required: [true, '请填写文章标题']
            },
            author: {
                type: mongoose.Schema.Types.ObjectId,
                ref: 'User',
                required: [true, '请填写作者']
            },
            publishDate: {
                type: Date,
                default: Date.now
            },
            cover: {
                type: String,
                default: null
            },
            content: {
                type: String
            }
        })
        //3.根据规则创建集合
    const Article = mongoose.model('Aticle', articleSchema);
    //4.将集合规则作为模块成员进行导出
    module.exports = {
        Article
    }



  • 相关阅读:
    Christmas Jump(k_push)
    cloudyarn(k_push)
    Eye sketch
    Candy Treasure Box
    Active Ball
    Lotus words
    Super Fish
    [POJ2436] Disease Management
    [bzoj3376] Cube Stacking 方块游戏
    [POJ3009] Curling 2.0
  • 原文地址:https://www.cnblogs.com/wahaha-/p/14194718.html
Copyright © 2011-2022 走看看