Mongoose select fields (nested)

后端 未结 1 1107
忘了有多久
忘了有多久 2021-01-04 18:27

I am trying to use the select operator in mongoose to select certain fields for the following object:

{
    \"_id\" : ObjectId(\"5249bb97a5de48bda3000003\"),         


        
相关标签:
1条回答
  • 2021-01-04 19:05

    You can use the same dot notation style in the select object with Mongoose as you do in your find example:

    var fields = { 'properties.OBJECTID': 1, 'properties.TIMESTAMP': 1 };
    var query = Feature.find({id: 1}).select(fields);
    

    You can also use a Mongoose style selection string:

    var query = Feature.find({id: 1})
        .select('properties.OBJECTID properties.TIMESTAMP');
    
    0 讨论(0)
提交回复
热议问题