• mangodb显示数据库数据


    api.js

    const bugs = require('../model/db').bugs;
    const ideas = require('../model/db').ideas;
    const express = require('express');
    const router = express.Router(http://www.amjmh.com/v/);

    router.get('/api/bugs/find', (function (req, res) {
    bugs.aggregate([{$sort: {create_date: -1}}] , function (err, results) {
    if(err){
    console.log("Error:" + err);
    res.send(err)
    }else{
    console.log(JSON.stringify(results));
    res.header('Access-Control-Allow-Origin', '*');
    res.send(JSON.stringify(results))
    }
    })
    }));

    router.post('/api/bugs/findSelf', (function (req, res) {
    bugs.aggregate([{$match: {"name": req.body.name}},{$sort: {create_date: -1}}] , function (err, results) {
    console.log(req.body.name);
    if(err){
    console.log("Error:" + err);
    res.send(err)
    }else{
    res.header('Access-Control-Allow-Origin', '*');
    res.send(results)
    }
    })
    }));

    router.get('/api/bugs/find_group', (function (req, res) {
    bugs.aggregate([{$group : {_id: "$name", _sum: {$sum : 1}}},{$sort: {_sum:-1}}] , function (err, results) {
    if(err){
    console.log("Error:" + err);
    res.send(err)
    }else{
    console.log(JSON.stringify(results));
    res.header('Access-Control-Allow-Origin', '*');
    res.send(JSON.stringify(results))
    }
    })
    }));

    router.post('/api/bugs/delete', (function (req, res) {
    bugs.deleteOne({"desc": req.body.desc}, function (err,results) {
    console.log(req.body.desc);
    if(err){
    console.log("Error:" + err);
    res.send(err)
    }else{
    res.header('Access-Control-Allow-Origin', '*');
    res.send(results)
    }
    })
    }));

    router.get('/api/ideas/find', (function (req, res) {
    ideas.aggregate([{$sort: {create_date: -1}}] , function (err, results) {
    if(err){
    console.log("Error:" + err);
    res.send(err)
    }else{
    console.log(JSON.stringify(results));
    res.header('Access-Control-Allow-Origin', '*');
    res.send(JSON.stringify(results))
    }
    })
    }));

    router.post('/api/ideas/findSelf', (function (req, res) {
    ideas.aggregate([{$match: {"name": req.body.name}},{$sort: {create_date: -1}}] , function (err, results) {
    console.log(req.body.name);
    if(err){
    console.log("Error:" + err);
    res.send(err)
    }else{
    res.header('Access-Control-Allow-Origin', '*');
    res.send(results)
    }
    })
    }));

    router.get('/api/ideas/find_group', (function (req, res) {
    ideas.aggregate([{$group : {_id: "$name", _sum: {$sum : 1}}},{$sort: {_sum:-1}}] , function (err, results) {
    if(err){
    console.log("Error:" + err);
    res.send(err)
    }else{
    console.log(JSON.stringify(results));
    res.header('Access-Control-Allow-Origin', '*');
    res.send(JSON.stringify(results))
    }
    })
    }));

    router.post('/api/ideas/delete', (function (req, res) {
    ideas.deleteOne({"desc": req.body.desc}, function (err,results) {
    console.log(req.body.desc);
    if(err){
    console.log("Error:" + err);
    res.send(err)
    }else{
    res.header('Access-Control-Allow-Origin', '*');
    res.send(results)
    }
    })
    }));

    module.exports = router;
    ---------------------

  • 相关阅读:
    The 16th Zhejiang Provincial Collegiate Programming Contest Sponsored(E F G H I)
    Ubuntu iso下载地址(14、16、18)
    JS解决在提交form表单时某个值不存在 alter弹窗点确定不刷新界面
    搞搞电脑微信表情的破解(.dat转png or jpg)
    12.29 模拟赛
    bzoj 2151 种树
    bzoj 5110 Yazid的新生舞会
    【系列】 点分治
    12.8 模拟赛
    12.17 模拟赛
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11325318.html
Copyright © 2020-2023  润新知