发布网友 发布时间:2022-05-02 10:22
共3个回答
懂视网 时间:2022-05-02 14:44
MongoClient = require(‘mongodb‘).MongoClient; const DB_CONN_STR = ‘mongodb://localhost:27017/test‘; let insertData = function(db, data, callback) { let collection = db.collection(‘person‘); collection.insert(data, function(err, result) { if (err) { console.log(‘Error:‘ + err); return; } callback(result); }) } MongoClient.connect(DB_CONN_STR, function(err, db) { console.log(‘连接成功!‘); let data = [{ "name": "tom", "age": "99" }]; insertData(db, data, function(result) { console.log(result); db.close(); }) selectData(db, function(result) { console.log(result); db.close(); }); })链接mysql的方式:
1.原始链接方式:
const mysql = require(‘mysql‘); let connection = mysql.createConnection({ host: ‘localhost‘, user: ‘root‘, password: ‘368532‘, database: ‘world‘ }); connection.connect(); connection.query(‘SELECT 1 + 1 AS solution‘, function(err, rows, fields) { if (err) throw err; console.log(‘The solution is: ‘, rows[0].solution); }); connection.end();
2.mysql中pool方式: mysql.createPool({})
3.使用中间件express-myconnection链接:
express数据库链接
标签:style const llb localhost 使用 mysq require expr pool
热心网友 时间:2022-05-02 11:52
Data Source=.\SQLEXPRESS;Integrated Security=True;User Instance=True热心网友 时间:2022-05-02 13:10
留下号码,远程协助