[SERVER-2162] support field exclusion for retrieving a subset of fields in a query Created: 30/Nov/10  Updated: 01/Dec/10  Resolved: 30/Nov/10

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: New Feature Priority: Major - P3
Reporter: Jeff Yemin (Inactive) Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Participants:

 Description   

There is support for retrieving a subset of fields in a find operation:

db.things.find(

{ x : 3 }

,

{ z : 1, y: 1 }

);

I would like the ability to retrieve all fields except a list of excluded fields, e.g.

db.things.find(

{ x : 3 }

, {$exclude : { z : 1, y: 1 }} );

This would retrieve all fields from matching documents except for z and y.

The reason this is important for us is because we have several large arrays that we add to every document that we use only for optimizing certain types of searches, but in normal use we don't need to have those fields returned when we actually perform the searches.



 Comments   
Comment by Eliot Horowitz (Inactive) [ 01/Dec/10 ]

No - it should be 0, sorry.

Comment by Jeff Yemin (Inactive) [ 01/Dec/10 ]

The example there uses 0, not -1, for exclusion. Will either work?

Comment by Eliot Horowitz (Inactive) [ 30/Nov/10 ]

Added a link in advanced.

Comment by Eliot Horowitz (Inactive) [ 30/Nov/10 ]

Its on here:
http://www.mongodb.org/display/DOCS/Retrieving+a+Subset+of+Fields

Comment by Jeff Yemin (Inactive) [ 30/Nov/10 ]

That is much more elegant. Can the advanced query doc be updated to reflect this? It wasn't obvious to me that you could do this.

Comment by Eliot Horowitz (Inactive) [ 30/Nov/10 ]

You can do

.find( { } ,

{ x : -1 }

)
to exclude x

Generated at Thu Feb 08 02:59:09 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.