3

I am populating _group in my role document

return this.find(query, {'_group': 1, 'name':1, 'description': 1} )
  .populate('_group', ['name', 'description'])
  .sort({ createdAt: -1 })
  ...

I get also the _id of the _group

{"_id":"5959ef7db9938a0600f05eb2",
"_group":{
    "_id":"5959ef7db9938a0600f05eae",
    "name":"GroupA",
     "description":"Description GroupA"
 },
"name":"manager",
"description":"can R group, can RW user"},

how can I get rid of the _group._id ?

I tried:

 return this.find(query, {'_group': 1, 'name':1, '_group._id':0, '_id':0} )

but it raises an error : Projection cannot have a mix of inclusion and exclusion.

and

return this.find(query, {'_group': 1, 'name':1, '_id':0, '_id':0}

removes only the role._id

thanks for feedback

1 Answers1

6
return this.find(query, {'_group': 1, 'name':1, 'description': 1} ).
    populate({
        path: '_group',
        select: 'name description -_id',
      }).sort({ createdAt: -1 })

Use this logic in your example

Prashant Tapase
  • 2,132
  • 2
  • 25
  • 34
  • Thanks a lot ... But what a strange way using minus and not 0 as for the doc Id... –  Jul 03 '17 at 07:53