There was no example of how to negate the in operator in the docs. …#2360
There was no example of how to negate the in operator in the docs. …#2360ppekrol merged 4 commits intoravendb:mainfrom
in operator in the docs. …#2360Conversation
…This is not obvious compared to how you would use the `in` operator
docs/querying/rql/what-is-rql.mdx
Outdated
| <TabItem> | ||
| ```csharp | ||
| from "Companies" | ||
| where exists(Name) and not Name in ("The Big Cheese", "Unknown company name") |
There was a problem hiding this comment.
It would be better to use true - this is what we do in the Client API
from "Companies"
where true and not Name in ("The Big Cheese", "Unknown company name")
There was a problem hiding this comment.
So I generated the following RQL from the Python client:
from 'Responses' where exists(user) and not user in ($p0)Which was printed from:
with self.document_store.open_session() as session:
query: DocumentQuery[dict[Any, Any]] = (
session
.query_collection("Responses")
.not_()
.where_in(field_name="user", values=("SL3789", "MB4557"))
)
print(query._to_string())And in the python client, there is no way to generate the RQL you stated:
def where_in(self, field_name: str, values: Collection, exact: Optional[bool] = None) -> DocumentQuery[_T]:
self._where_in(field_name, values, exact)
return selfSince field_name is a required field. And then in the RQL generator, there is no option to enter the else condition from where_in since field_name is always required:
def __negate_if_needed(self, tokens: List[QueryToken], field_name: Optional[str]) -> None:
if not self._negate:
return
self._negate = False
if not tokens or isinstance(tokens[-1], OpenSubclauseToken):
if field_name is not None:
self._where_exists(field_name)
else:
self._where_true()
self._and_also()
tokens.append(NegateToken.instance())I do agree with your example you gave in your comment, since in the case where the field user does not exist, I would also want to return documents. Should I submit a ticket in the python client repo for this?
There was a problem hiding this comment.
Hmm, no need, I wrote it down to check in all the Client APIs, thanks!
…lt set is different based on the provided condition
| where true and not Name in ("The Big Cheese", "Unknown company name") | ||
| ``` | ||
| </TabItem> | ||
|
|
There was a problem hiding this comment.
Putting aside the separate issue of the Client API Not generating the where true clause in the produced RQL,
the documentation here should explain the actual RQL rule.
The following ContentFrame block should be used for the in operator:
<ContentFrame>
#### Operator: `in`
The `in` operator evaluates a field against a list of values.
It will return results if the field matches **any** of the items in that list.
<TabItem>
```csharp
from "Companies"
where Name in ("The Big Cheese", "Unknown company name")
```
</TabItem>
<TabItem>
```csharp
from "Orders"
where Lines[].ProductName in ("Chang", "Spegesild", "Unknown product name")
```
</TabItem>
---
**To negate an `in` condition**, use the `NOT` operator.
However, in RQL, `NOT` is not used as a standalone operator at the start of a `where` expression.
Therefore, the negated condition must follow some **valid preceding expression**.
For example:
<TabItem>
```csharp
from "Companies"
where true and NOT Name in ("The Big Cheese", "The Cracker Box")
```
</TabItem>
Instead of `where true`, any valid preceding expression can be used, even one that references a different field.
For example:
<TabItem>
```csharp
from "Companies"
where exists(SomeFieldName) and NOT Name in ("The Big Cheese", "The Cracker Box")
```
</TabItem>
</ContentFrame>
…should be more focused on explaining the actual RQL rule
|
@slidwell44, please note:
|
This is now more concise and directly addresses the preferred pattern for negating the `IN` condition
|
That makes sense to me. When I tested out the other conditions in your note, I do see a use case for |
…This is not obvious compared to how you would use the
inoperatorIssue link
https://issues.hibernatingrhinos.com/issue/RDoc-...
Additional description
Include details of the change made, paste screenshots if necessary, and add anything that may be useful for the reviewers.
Type of change
/templatesor README)Changes in docs URLs
/scripts/redirects.json, set theDocuments MovedPR label)Changes in UX/UI