MongoDB+nodejs查询并返回数据

const express = require('express');
const router = express.Router();


const Monk = require('monk');
const Db = new Monk('localhost:27017/dictionary');//连接mongoDb地址

//返回数据接口
router.get('/getData', async function(req, res) {
  let data1 = await Db.get('data').find();
  res.json({
    code : 2000,
    data : data1
  })
});

posted @ 2018-08-16 11:15  琪思妙想  阅读(3917)  评论(0编辑  收藏  举报