明树Git Lab

Commit 708a5641 authored by zfp1's avatar zfp1

update

parent a53e05ea
......@@ -19,7 +19,8 @@ const collectIndustryEnvironmentalTestingSchema = new Schema({
time: {
type: Date,
get: v => moment(v).format("YYYY-MM-DD HH:mm:ss"),
comment: "采集时间"
comment: "采集时间",
default: new Date()
},
/*---------------------------------------------*/
......
......@@ -3,6 +3,19 @@ const { MongoClient } = require('mongodb');
const iconv = require('iconv-lite');
let mongourl = `mongodb://root:letian2024.@172.16.0.16:27017/letian?authSource=admin`; //内网
const client = new MongoClient(mongourl);
let collection = null;
(async function () {
// 连接到 MongoDB 服务器
console.log(' 正在连接 MongoDB...');
await client.connect();
console.log('✅ MongoDB 连接成功');
// 获取数据库和集合
const db = client.db("letian");
collection = db.collection("collectIET");
})();
const server = net.createServer((socket) => {
......@@ -125,22 +138,7 @@ function genInsertObj(gbkString, deviceNumber) {
async function connectAndInsert(data) {
// 创建 MongoDB 客户端
const client = new MongoClient(mongourl, {
useNewUrlParser: true,
useUnifiedTopology: true,
serverSelectionTimeoutMS: 5000, // 5秒连接超时
});
try {
// 连接到 MongoDB 服务器
console.log(' 正在连接 MongoDB...');
await client.connect();
console.log('✅ MongoDB 连接成功');
// 获取数据库和集合
const db = client.db("letian");
const collection = db.collection("collectIET");
// 插入单个文档
console.log(' 正在插入数据...');
const insertResult = await collection.insertOne(data);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment