[SERVER-16896] Provide "is subset" array functionality in query predicate language Created: 16/Jan/15  Updated: 06/Dec/22  Resolved: 20/Apr/17

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

Type: New Feature Priority: Major - P3
Reporter: Kevin Pulo Assignee: Backlog - Query Team (Inactive)
Resolution: Duplicate Votes: 4
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-9366 Expose projection (aggregation) opera... Closed
Duplicate
duplicates SERVER-974 $subset query operator Closed
Assigned Teams:
Query
Backwards Compatibility: Fully Compatible
Participants:

 Description   
Summary

$only would select the document where the queried field is an array that only contains the specified values. (If the queried field isn't an array, then the operator is identical to $in.)

Example

> db.foo.drop()
> db.foo.insert( { a: [ "a", "b" ] } )
> db.foo.insert( { a: [ "a", "d" ] } )
> db.foo.insert( { a: [ "d", "e" ] } )
> db.foo.find( { a: { $in: [ "a", "b", "c" ] } } )
{ a: [ "a", "b" ] }
{ a: [ "a", "d" ] }
> db.foo.find( { a: { $only: [ "a", "b", "c" ] } } )
{ a: [ "a", "b" ] }

More details

$nin already has semantics of checking all elements in the document array to make sure none of them are in the supplied array. This suggestion is just like that, except it should check that every element is in the target array (instead of is not in the target array as $nin does). i.e. compare the above to:

> db.foo.find( { a: { $nin: [ "a", "b", "c" ] } } )
{ a: [ "d", "e" ] }

$all is not what I'm looking for:

> db.foo.find( { a: { $all: [ "a", "b", "c" ] } } )
> 



 Comments   
Comment by Nicholas Zolnierz [ 20/Apr/17 ]

Marking as duplicate of SERVER-974 as the behavior of $only is identical to the desired behavior of $subSet.

Comment by J Rassi [ 20/May/15 ]

This functionality is already available in the aggregation framework with the $setIsSubset operator.

It is possible that this functionality will be exposed via $setIsSubset in the query predicate language by SERVER-9366, instead of via a dedicated $only operator. I've added a dependency of this ticket on SERVER-9366, so we'll re-evaluate after that ticket is resolved.

Generated at Thu Feb 08 03:42:38 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.