app.get('/',function(req,res){
var response={};
db.collection('first').find({},function(err,result){
if(err){
db.close();
console.log('Error');
console.log(err);
}
else{
db.close();
console.log('Success');
console.log(response);
}
});
res.end(response);
});
Run Code Online (Sandbox Code Playgroud)
但是,这会返回大量不需要的数据.我也查看了这些数据,但是我没有看到集合中的条目值/字段.我希望它仅将字段值作为JSON对象返回.我该怎么做?
样本输出:(发布所有内容太多)
Readable {
connection: null,
server: null,
disconnectHandler:
{ s: { storedOps: [], storeOptions: [Object], topology: [Object] },
length: [Getter] },
bson: {},
ns: '****',
cmd:
{ find: '******',
limit: 0,
skip: 0,
query: {},
slaveOk: true,
readPreference: { preference: 'primary', tags: undefined, options: undefined } },
options:
{ skip: 0,
limit: 0,
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: …Run Code Online (Sandbox Code Playgroud) 我的节点应用程序正在侦听端口8080.当我添加时
app.listen(port,'50.30.217.289');
Run Code Online (Sandbox Code Playgroud)
我可以从浏览器访问该应用程序.但是当我用我的EC2实例的弹性IP地址替换IP地址时,我收到一个错误:
EADDRNOTAVAIL
我该如何解决 ?