Meteor js: create index in user collection

I am creating a collection of users with a full name (for example, Jose Osorio, Jose castro, John smith, Maria Smith), I need to create a search bar to find registered users by their first name or last name.

those. write in the search bar and I want to see Jose Osorio and Jose Castro.

I read about creating an index in a database, but it didn’t work, or I did it wrong, what can I do to solve this problem?

+4
source share
3 answers

To add an index:

Meteor.startup(function () {  
  Meteor.users._ensureIndex({ "fullname": 1});
});

and make a collector, see: https://atmospherejs.com/fourq/typeahead

+7
source

rawCollection :

Products.rawCollection().createIndex({
    "type": "text",
    "searchString": "text",
    "title": "text",
    "brand": "text",
    "description": "text"
}, { 
    "weights": {
        type: 5,
        brand: 4,
        title: 3,
        searchString: 3,
        description: 1
    }
});
+6

, , , db.books.createIndex( { "category": 1 } ) mongo.

+3

Source: https://habr.com/ru/post/1607167/


All Articles