mongoose 的使用
const mongoose = require('mongoose'); mongoose .connect('mongodb://admin:sss.com@101.227.109.7:27017/GIS?authSource=admin', { useUnifiedTopology: true, useNewUrlParser: true, }) .then(() => { console.log('连接成功'); }) .catch((e: any) => { console.log('连接错误:', e); }); const Schema = mongoose.Schema; const grid1080_1920 = new Schema({ _id: String, airport: String, camera_direction: String, point_data: Object, index_data: Object, gis_data: Object, camera_id: String, }); const Blog = mongoose.model('grid1080_1920', grid1080_1920); let a = () => { return new Promise(function (resolve, reject) { Blog.find().then((data: any) => { resolve(data); }); }); }; let sth = await a(); mongoose.connection.close(); ctx.body = sth;
漫思