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

451
Visualizações
Username full text search in Meteor.users

I am trying to search the meteor.users collection by username.

I have followed all the steps detailed here, but I can't seem to make it work meteor.users.

Here is the code I have for that:

On Server Startup:

Meteor.startup(function(){
  Meteor.users._ensureIndex({
    "username":"text",
  });
});

In my publish function:

Meteor.publish("Meteor.users.userSearch",function(searchVal){

  if(!searchVal){
   return Meteor.users.find({});
  }

  return Meteor.users.find({$text:{$search:searchVal}});

});

On the client:

Template.foo.helpers({
  users(){
    var searchValue = Session.get('searchVal');
    Meteor.subscribe('Meteor.users.userSearch',searchValue);
    return Meteor.users.find({});
  }
});

Can someone please help me figure out what is wrong with the above?

When there is no searchValue, it works correctly and all the users are returned. As soon as there is any search value, no users are returned at all.

I have also tried directly in the mongodb console db.users.find({$text:{$search:"some_test"}}) and again there is no collection object returned.

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

0

You do not need to do full text search if you just want to search value of only one field (username in this case). Using normal find command with Regex value as search value is better in this case:

Meteor.users.find({
  username: new RegExp('user1', 'gi'),
});
over 4 years ago · Santiago Trujillo Relatório

0

ensureIndex: Deprecated since version 3.0.0: db.collection.ensureIndex() is now an alias for db.collection.createIndex().

_ensureIndex appears to be an orphan.

Meteor.startup(function(){
  Meteor.users.createIndex({
    "username":"text"
  });
});
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