我有一个连接到NodeJs服务器的android(java)应用程序。当我在本地运行服务器时,一切运行正常,但是当我将节点服务器部署到horeku时,运行该代码段时服务器崩溃
app.post('/facture',(request, response,next)=>{
var post_data = request.body;
var date_insertion = post_data.date_insertion;
console.log("Date "+post_data.date_insertion);
var Creator = post_data.Creator;//getname
console.log("Creator "+post_data.Creator);
var Email_col = post_data.Email_col;//getemail
var Product = post_data.Product;//getcleint
var TotalePrix = post_data.TotalePrix;//getproduct
var Lat = post_data.Lat;//getPrix
var Long = post_data.Long;
var type = post_data.type;
//type ="collection";
var insertJSON1 = {
'Creator':Creator,
'date_insertion':date_insertion,
'Email_col':Email_col,
'Product':Product,
'TotalePrix':TotalePrix,
'Lat':Lat,
'Long':Long,
'type':type
};
var db = client.db('transpertor');
//Insertion des données
db.collection('facture').insertOne(insertJSON1,function(error,res){
if(error) throw error;
response.json('L entregistrement des infos a été effectuer avec sucess');
console.log('L entregistrement des infos a été effectuer avec sucess');
});
});
Rq:当我执行该代码时,应用会在1秒后自动执行:
app.post('/collect/get',(request,response,next)=>{
var post_data = request.body;
var selector = post_data.selector;
//console.log(post_data.selector);
//var selector = "all";
var db = client.db('transpertor');
if(selector == "all"){
db.collection('collection').find({}).count(function(err,number){
if(err) console.log(err);
console.log("number "+number);
if(number ==0){
response.json('collection is empty');
console.log('collection is empty');
}else{
db.collection('collection').find({}).toArray(function(err,result){
if(err) console.log(err);
response.json(result);
//console.log(result);
});
}
});
}else{
db.collection('collection').find({'emailcol':selector}).count(function(err,number){
if(number ==0){
response.json('Col not exist');
console.log('Col not exist');
}else{
db.collection('collection').findOne({'emailcol':selector},function(err,res){
if(err) console.log(err);
response.json(res);
console.log('Sending scess!');
});
}
});
}
});
Horeku日志显示:
2020-02-12T08:59:59.312142 + 00:00 heroku [web.1]:状态从上更改 崩溃了2020-02-12T08:59:59.114743 + 00:00 heroku [router]:at = error code = H13 desc =“连接已关闭但无响应” method = POST path =“ / facture” host = transportorfirst.herokuapp.com request_id = a18e809a-f632-479a-b8ee-238ef15f0e79 fwd =“ 196.203.182.5” dyno = web.1 connect = 5ms服务= 155ms状态= 503字节= 0协议= https 2020-02-12T08:59:58.971115 + 00:00 app [web.1]:日期2020-02-12 09:59:29 2020-02-12T08:59:58.971867 + 00:00 app [web.1]:创建者 ala.freestyle00@gmail.com 2020-02-12T08:59:59.072170 + 00:00 app [web.1]: /app/node_modules/mongodb/lib/utils.js:133 2020-02-12T08:59:59.072178 + 00:00 app [web.1]:抛出错误; 2020-02-12T08:59:59.072182 + 00:00 app [web.1]:^ 2020-02-12T08:59:59.072183 + 00:00 app [web.1]: 2020-02-12T08:59:59.072194 + 00:00 app [web.1]:MongoWriteConcernError: 在副本集中找不到名为“ oritymaj”的写关注模式 配置2020-02-12T08:59:59.072207 + 00:00应用程序[web.1]:在 连接。 (/app/node_modules/mongodb/lib/core/connection/pool.js:461:23) 2020-02-12T08:59:59.072207 + 00:00 app [web.1]:在Connection.emit (events.js:321:20)2020-02-12T08:59:59.072208 + 00:00 app [web.1]:at processMessage (/app/node_modules/mongodb/lib/core/connection/connection.js:384:10) 2020-02-12T08:59:59.072208 + 00:00 app [web.1]:位于TLSSocket。 (/app/node_modules/mongodb/lib/core/connection/connection.js:553:15) 2020-02-12T08:59:59.072208 + 00:00 app [web.1]:位于TLSSocket.emit (events.js:321:20)2020-02-12T08:59:59.072209 + 00:00 app [web.1]:at addChunk(_stream_visible.js:294:12)2020-02-12T08:59:59.072210 + 00:00 app [web.1]:位于可读AddChunk(_stream_visible.js:275:11) 2020-02-12T08:59:59.072211 + 00:00 app [web.1]:在 TLSSocket.Readable.push(_stream_visible.js:209:10) 2020-02-12T08:59:59.072212 + 00:00 app [web.1]:在TLSWrap.onStreamRead (internal / stream_base_commons.js:186:23){ 2020-02-12T08:59:59.072212 + 00:00 app [web.1]:代码:79, 2020-02-12T08:59:59.072213 + 00:00 app [web.1]:代号: 'UnknownReplWriteConcern',2020-02-12T08:59:59.072213 + 00:00 app [web.1]:errmsg:“在以下位置找不到名为'oritymaj'的写关注模式 副本集配置”,2020-02-12T08:59:59.072214 + 00:00 app [web.1]:名称:“ MongoWriteConcernError”, 2020-02-12T08:59:59.072214 + 00:00 app [web.1]:结果:{ 2020-02-12T08:59:59.072214 + 00:00 app [web.1]:n:1, 2020-02-12T08:59:59.072215 + 00:00 app [web.1]:opTime:{ts: [时间戳记],t:2},2020-02-12T08:59:59.072215 + 00:00 app [web.1]: lectionId:7fffffff0000000000000002,2020-02-12T08:59:59.072215 + 00:00 app [web.1]:确定:1,2020-02-12T08:59:59.072216 + 00:00 app [web.1]: writeConcernError:{2020-02-12T08:59:59.072216 + 00:00 app [web.1]: 代码:79,2020-02-12T08:59:59.072217 + 00:00应用程序[web.1]:代码名称: 'UnknownReplWriteConcern',2020-02-12T08:59:59.072217 + 00:00 app [web.1]:errmsg:“在以下位置找不到名为'oritymaj'的写关注模式 副本集配置” 2020-02-12T08:59:59.072218 + 00:00 app [web.1]:},2020-02-12T08:59:59.072218 + 00:00 app [web.1]: '$ clusterTime':{clusterTime:[Timestamp],签名:[Object]}, 2020-02-12T08:59:59.072219 + 00:00 app [web.1]:operationTime:Timestamp { bsontype:'Timestamp',low :1,high_:1581497999} 2020-02-12T08:59:59.072219 + 00:00 app [web.1]:}, 2020-02-12T08:59:59.072219 + 00:00 app [web.1]: [Symbol(mongoErrorContextSymbol)]:{} 2020-02-12T08:59:59.072220 + 00:00 app [web.1]:} 2020-02-12T08:59:59.133019 + 00:00 app [web.1]:npm错误! 代码ELIFECYCLE 2020-02-12T08:59:59.133607 + 00:00 app [web.1]:npm ERR! errno 1 2020-02-12T08:59:59.139922 + 00:00 app [web.1]:npm ERR! transportor@1.0.0开始:
node index.js
2020-02-12T08:59:59.140189 + 00:00 app [web.1]:npm ERR!退出状态1 2020-02-12T08:59:59.149789 + 00:00 app [web.1]:npm ERR! 2020-02-12T08:59:59.150081 + 00:00 app [web.1]:npm ERR!失败于 transportor@1.0.0启动脚本。 2020-02-12T08:59:59.150320 + 00:00 app [web.1]:npm错误! npm可能不是问题。有 可能上面有其他日志记录输出。 2020-02-12T08:59:59.191980 + 00:00 app [web.1]: 2020-02-12T08:59:59.196457 + 00:00 app [web.1]:npm ERR!完整的日志 您可以在2020-02-12T08:59:59.196656 + 00:00中找到此运行 app [web.1]:npm错误!
/app/.npm/_logs/2020-02-12T08_59_59_151Z-debug.log 2020-02-12T08:59:59.299537 + 00:00 heroku [web.1]:进程退出 状态1 2020-02-12T09:00:01.648371 + 00:00 heroku [router]:at = error code = H10 desc =“应用程序崩溃”方法= POST路径=“ / collect / get” host = transportorfirst.herokuapp.com request_id = 2f3d6c30-9670-40b7-9f11-e0738cf31bf0 fwd =“ 196.203.182.5” dyno = connect = service = status = 503字节= protocol = https
但是我发现并没有每次都触发暗恋,并且如果我的服务器崩溃了,我会发现我的ATlas MongoDB具有新信息。