Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.where selector is mandatory when using .select or .partialIndex #1216

Open
paultranvan opened this issue Aug 4, 2022 · 4 comments · Fixed by #1225
Open

.where selector is mandatory when using .select or .partialIndex #1216

paultranvan opened this issue Aug 4, 2022 · 4 comments · Fixed by #1225

Comments

@paultranvan
Copy link
Contributor

When a query is run without a selector and sort, the Collection.all will be used: https://github.com/cozy/cozy-client/blob/master/packages/cozy-client/src/StackLink.js#L86-88.
For instance:

client.find(Q(doctype).partialIndex({trashed: false}).fields(['trashed', 'dir_id', 'name']))

Furthermore, a sort cannot be used without a selector according to #405

When the Collection.all is used, some query options cannot work such as .partialIndex or .select, as the _all_docs API will be used , that does not support such features.

trollepierre added a commit to cozy/cozy-drive that referenced this issue Aug 5, 2022
Selector is mandatory when using .select or .partialIndex
cozy/cozy-client#1216
trollepierre added a commit to cozy/cozy-drive that referenced this issue Aug 5, 2022
Selector is mandatory when using .select or .partialIndex
cozy/cozy-client#1216
trollepierre added a commit to cozy/cozy-drive that referenced this issue Aug 8, 2022
Selector is mandatory when using .select or .partialIndex
cozy/cozy-client#1216
trollepierre added a commit to cozy/cozy-drive that referenced this issue Aug 8, 2022
Selector is mandatory when using .select or .partialIndex
cozy/cozy-client#1216
trollepierre added a commit to cozy/cozy-drive that referenced this issue Aug 8, 2022
Selector is mandatory when using .select or .partialIndex
cozy/cozy-client#1216
trollepierre added a commit to cozy/cozy-drive that referenced this issue Aug 10, 2022
Selector is mandatory when using .select or .partialIndex
cozy/cozy-client#1216
trollepierre added a commit to cozy/cozy-drive that referenced this issue Aug 10, 2022
Selector is mandatory when using .select or .partialIndex
cozy/cozy-client#1216
trollepierre added a commit to cozy/cozy-drive that referenced this issue Aug 10, 2022
Selector is mandatory when using .select or .partialIndex
cozy/cozy-client#1216
@paultranvan
Copy link
Contributor Author

This issue still exists for contacts because of: https://github.com/cozy/cozy-client/blob/master/packages/cozy-stack-client/src/ContactsCollection.js#L13
If a query has no selector but a partialFilter, this will fail, as found by @cballevre

@Crash-- Crash-- reopened this Mar 29, 2023
@JF-Cozy
Copy link
Contributor

JF-Cozy commented Mar 29, 2023

Petit souci également avec une requête de ce type

export const buildContactsQuery = (enabled = true) => ({
  definition: () =>
    Q(CONTACTS_DOCTYPE)
      .select([
        'name',
        'displayName',
        'fullname',
        ...
      ])
      .limitBy(1000),
  options: {
    as: CONTACTS_DOCTYPE,
    fetchPolicy: defaultFetchPolicy,
    enabled
  }
})

génère l'erreur suivante :

error: "missing_required_key"
ok: false
reason: "Missing required key: selector"
status: "400"

l'astuce pour l'instant consiste à rajouter _id dans le select et un .where({ _id: { $gt: null } })

@paultranvan
Copy link
Contributor Author

CouchDB expect a mandatory selector for mango queries: https://docs.couchdb.org/en/stable/api/database/find.html#db-find

@Merkur39
Copy link
Member

Merkur39 commented Feb 7, 2024

Up, un nouveau souci trouvé aujourd'hui, avec cette définition :

Q(GEOJSON_DOCTYPE)
    .indexFields(['cozyMetadata.sourceAccount'])
    .sortBy([{ 'cozyMetadata.sourceAccount': 'desc' }])
    .limitBy(1000)

Elle génère la même erreur que ci-dessus

error: "missing_required_key"
ok: false
reason: "Missing required key: selector"
status: "400"

Elle reste contournable avec l'ajout d'un .where({})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants