小编dpm*_*dpm的帖子

MongoDb find()返回许多不需要的字段

 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)

rest mongodb node.js

1
推荐指数
1
解决办法
486
查看次数

EADDRNOTAVAIL仅在使用EC2实例时

在此输入图像描述

在此输入图像描述

在此输入图像描述

我的节点应用程序正在侦听端口8080.当我添加时

app.listen(port,'50.30.217.289');
Run Code Online (Sandbox Code Playgroud)

我可以从浏览器访问该应用程序.但是当我用我的EC2实例的弹性IP地址替换IP地址时,我收到一个错误:

EADDRNOTAVAIL

我该如何解决 ?

amazon-ec2 amazon-web-services node.js aws-ec2

1
推荐指数
1
解决办法
1704
查看次数