How to exclude one particular field from a collection in Mongoose?

前端 未结 6 2160
逝去的感伤
逝去的感伤 2020-12-13 12:15

I have a NodeJS application with Mongoose ODM(Mongoose 3.3.1). I want to retrieve all fields except 1 from my collection.For Example: I have a collection Pr

6条回答
  •  悲哀的现实
    2020-12-13 12:32

    I don't know where you read about that .exclude function, because I can't find it in any documentation.

    But you can exclude fields by using the second parameter of the find method.

    Here is an example from the official documentation:

    db.inventory.find( { type: 'food' }, { type:0 } )
    

    This operation returns all documents where the value of the type field is food, but does not include the type field in the output.

提交回复
热议问题