-
Notifications
You must be signed in to change notification settings - Fork 4
PHPLIB-1340 Remove Projection Operators #54
Conversation
073eaf3
to
b1300df
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you crossed out the positional operator ($). Is there no work to be done for that?
comments: | ||
# Example uses the short form, the builder always generated the verbose form | ||
# $slice: 3 | ||
$slice: [3] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem correct, as the docs indicate that the array form requires both elements:
Specifies the number of elements to return in the after skipping the specified number of elements starting from the first element. You must specify both elements.
Also, the short form is $slice: <number to return>
. When an array form is used, the first value specifies the number to skip and <number to return>
is the second value.
I would hope the server would just error on this since it's ambiguous, although I could see a case where is accepted and allows $slice
to skip a few elements and return everything else. The server docs don't suggest that's possible, so I assume you can only accomplish that by specifying a very large <number to return>
and hoping it exceeds the array size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we will need a custom encoder.
$slice: [3]
returns a server error.
MongoServerError: Invalid $slice syntax. The given syntax { $slice: [ 3 ] } did not match the find() syntax because :: Location31272: $slice array argument should be of form [skip, limit] :: The given syntax did not match the expression $slice syntax. :: caused by :: Expression $slice takes at least 2 arguments, and at most 3, but 1 were passed in.
Note: the version with 3 arguments is not documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the version with 3 arguments is not documented
I apologize for the headache, but that sounds like it warrants a DOCSP ticket. And make sure to tell them you shouldn't be used as the technical reviewer when/if it actually gets implemented (this frequently happens to me when I report server docs issues). It should really be someone from server, since they'll have to confirm what it actually does.
And if it should remain undocumented, server should consider revising this error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
{ | ||
$pipeline = new Pipeline( | ||
Stage::project( | ||
comments: Projection::slice(-1, 3), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the argument order for Projection::slice
will need to change, and I can see this being confusing for users since it will differ from the server API.
Both the short and long forms accept a <number to return>
value, and the long form also accepts <number to skip>
. If the PHP API is going to provide a consistent API without using named parameters, <number to skip>
should be an optional second parameter.
Maybe something similar to fieldpath then? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the positional operator can occur anywhere within a field path, I'm not certain a separate builder method is necessary unless you intend to enforce some typing with it and assert that it's well formed (such as ".$" at the end of a path or ".$." within a path).
I'm not convinced that's needed, though.
I decided to remove all projection operators. They can't be used in |
Fix PHPLIB-1340
The projection operators can only be used with the
find
command.https://www.mongodb.com/docs/manual/reference/operator/query/#projection-operators
no operator$
$elemMatch
covered by PHPLIB-1363 PHPLIB-1355 Add enum for$meta
$type
query and$meta
expression #38$slice
Also removed
$filter
from Projection operators, as it's an Expression operator.