text: "use strict"
  const mongoose = require('mongoose');
  const mongoDB = require('../config.json').mongodb;
  mongoose.connect(mongoDB);
  let articleSchema = new mongoose.Schema({
      article_author: String,
      article_date: {type: Date, default: Date.now()},
      article_title: String,
      article_content: String,
      category_id: String
  });
  
  let Article = mongoose.model('Article', articleSchema);
  
  //获得文章列表
  function getArticles(categoryId) {
      return Article.find(categoryId ? {category_id: categoryId} : {});
  }
  
  //获得文章数量
  //todo 需使用arguments
  function getArticleSize(categoryId) {
      return Article.find(categoryId ? {category_id: categoryId} : {}, {_id: 1},{});
  }
  
  //获得文章标题列表
  function getArticlesTitle() {
      return Article.find({}, {_id: 1, article_title:1},{});
  }
  
  //获得单篇文章
  function getArticle(id) {
      return Article.findOne({_id: id});
  }
  
  //添加文章
  function addArticle(articleData) {
      return Article.create(articleData);
  }
  
  //删除文章
  function deleteArticle(id) {
      return Article.remove({_id: id});
  }
  
  //修改文章
  function editArticle(articleData) {
      console.log(articleData);
      return Article.update({"_id": articleData._id}, {
          $set: {
              "article_author": articleData.article_author,
              "article_date": articleData.article_date,
              "article_title": articleData.article_title,
              "article_content": articleData.article_content,
              "category_id": articleData.category_id,
          }
      });
  }
  
  
  
  //获得最新发布的文章时间
  function getArticleDate() {
      return Article.findOne().sort({article_date:1}).limit(1);
  }
  
  module.exports.getArticles = getArticles;
  module.exports.getArticlesTitle = getArticlesTitle;
  module.exports.addArticle = addArticle;
  module.exports.getArticle = getArticle;
  module.exports.deleteArticle = deleteArticle;
  module.exports.editArticle = editArticle;
  module.exports.getArticleSize = getArticleSize;
  module.exports.getArticleDate = getArticleDate;