Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

243
Visualizações
RavenDB can't perform search with AND operator on nodejs

How can I perform a search with 'AND' operator via RavenDB?

Based on the docs it's written that I need to add the operator enum ("AND" \ "OR") as the third parameter of the search function. https://ravendb.net/docs/article-page/4.0/nodejs/client-api/session/querying/how-to-use-search

From some reason the AND operator does not work and it gives me OR results by default.

Example:

Users collection:

users/1-A: {
    firstName: 'Joe',
    lastName: 'Allen'
}

users/2-A: {
    firstName: 'Joe',
    lastName: 'Biden'
}

The call to raven:

session.query({ collection: 'Users' })
.search('firstName', 'Joe', 'AND') // search with AND operator
.search('lastName', 'Biden')
.all()

The call above returns back both documents. What should be the appropriate syntax for that?

Thanks

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

You can find detailed examples & walkthrough explanations in the following RavenDB demos:

https://demo.ravendb.net/demos/csharp/text-search/fts-query-search-basics https://demo.ravendb.net/demos/csharp/text-search/fts-query-search-operators

So this here above is currently only for C# client (nodeJS demos are TBD)

When using 2 separate search methods:
Then the other answer here - about using andAlso - is correct

When using single search method:
Using AND/OR is relevant only when you have 2 or more terms within the same search method.

i.e.:
.search('firstName', 'John Doe', 'AND')
will AND both terms (John && Doe)

.search('firstName', 'John Doe', 'OR')
will OR the results (John || Doe)

over 4 years ago · Santiago Trujillo Relatório

0

So I found a solution for node.js. The "AND" enum as a third parameter did not work for me (according to this page: https://ravendb.net/docs/article-page/4.0/nodejs/client-api/session/querying/how-to-use-search).

I foundo another page: https://ravendb.net/docs/article-page/4.0/nodejs/indexes/querying/searching

Which uses andAlso() function on the query to use the "AND" operator and it works.

Example:

const joeBiden = session.query({ collection: 'Users' })
.search('firstName', 'Joe')
.andAlso()
.search('lastName', 'Biden')
.all()

This will return only Joe Biden's document.

Please note that it returns a promise.

** Raven will raise an error if you call the andAlso function and no query after it, so if you loop through possible search terms remember to exclude the andAlso function in the last search.

const joeBiden = session.query({ collection: 'Users' })
    .search('firstName', 'Joe')
    .andAlso()
    .search('lastName', 'Biden')
    .andAlso() // this line will cause Raven to throw an error
    .all()
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda