zoukankan      html  css  js  c++  java
  • 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;
    ---------------------

  • 相关阅读:
    架构之道(1)
    看板管理(1)
    交互原型图
    Sequence Diagram时序图
    安卓项目的「轻」架构
    安卓ButtomBar实现方法
    工具类BitMap 把网络URL图片转换成BitMap
    使用OkHttp上传图片到服务器
    BaseAdapter教程(2) BaseAdapter的notifyDataSetChanged动态刷新
    开发中时间变换问题汇总
  • 原文地址:https://www.cnblogs.com/hyhy904/p/11325318.html
Copyright © 2011-2022 走看看