第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關(guān)于 express 中使用 mongodb 第二次失敗問題十分感謝

關(guān)于 express 中使用 mongodb 第二次失敗問題十分感謝

qq_笑_17 2019-08-21 19:37:06
-問題描述最近在學(xué)習(xí)使用express和mongodb;做了demo例子,發(fā)現(xiàn)個問題,就是每次從頁面上發(fā)送請求往表里添加數(shù)據(jù)時,第一次正常,第二次就報錯了?-對應(yīng)代碼express版本4.16.4mongodb版本3.1.10//expressconstexpress=require('express')constbodyParser=require('body-parser')constapp=express()//mongodbconsturlDB='mongodb://localhost:27017'constMongoClient=require('mongodb').MongoClientconstClient=newMongoClient(urlDB,{useNewUrlParser:true})//mongodbfunctionconstinsertDoc=function(db,collectionName,data,callback){constcollection=db.collection(collectionName)collection.insertOne(data,(err,res)=>{callback&&callback(err,res)})}app.use(bodyParser.urlencoded({extended:true}))//使用虛擬目錄的靜態(tài)服務(wù)app.use('/static',express.static('public'))//路由app.get('/',(req,res)=>{res.sendFile(__dirname+'/index.html')})//應(yīng)用app.post('/insert',(req,res)=>{//mongodbClient.connect((err)=>{constdb_=Client.db('user')console.log('-連接成功-',err);insertDoc(db_,'user',req.body,(errDB,resDB)=>{if(errDB){console.log('-插入失敗-',errDB);res.send({succ:false})}else{resDB.result.ok&&res.send({succ:true})Client.close()}})})})//端口號app.listen(3000)-錯誤代碼theoptions[servers]isnotsupportedtheoptions[caseTranslate]isnotsupported-連接成功-null-插入失敗-{MongoError:serverinstancepoolwasdestroyedatbasicWriteValidations(/Users/chisecj/Documents/project/study/test_node/09_express/node_modules/_mongodb-core@3.1.9@mongodb-core/lib/topologies/server.js:700:41)atServer.insert(/Users/chisecj/Documents/project/study/test_node/09_express/node_modules/_mongodb-core@3.1.9@mongodb-core/lib/topologies/server.js:805:16)atServer.insert(/Users/chisecj/Documents/project/study/test_node/09_express/node_modules/_mongodb@3.1.10@mongodb/lib/topologies/topology_base.js:321:25)atinsertDocuments(/Users/chisecj/Documents/project/study/test_node/09_express/node_modules/_mongodb@3.1.10@mongodb/lib/operations/collection_ops.js:838:19)atinsertOne(/Users/chisecj/Documents/project/study/test_node/09_express/node_modules/_mongodb@3.1.10@mongodb/lib/operations/collection_ops.js:868:3)atexecuteOperation(/Users/chisecj/Documents/project/study/test_node/09_express/node_modules/_mongodb@3.1.10@mongodb/lib/utils.js:420:24)atCollection.insertOne(/Users/chisecj/Documents/project/study/test_node/09_express/node_modules/_mongodb@3.1.10@mongodb/lib/collection.js:464:10)atinsertDoc(/Users/chisecj/Documents/project/study/test_node/09_express/app.js:12:14)atClient.connect(/Users/chisecj/Documents/project/study/test_node/09_express/app.js:30:5)atresult(/Users/chisecj/Documents/project/study/test_node/09_express/node_modules/_mongodb@3.1.10@mongodb/lib/utils.js:414:17)name:'MongoError',[Symbol(mongoErrorContextSymbol)]:{}}
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 779 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號