Jose Osorio
Jose Osorio

Reputation: 939

Meteor js: Create index in user collection

I create a user collection with a fullname field (i.e. Jose Osorio, Jose castro, John smith, Maria Smith), I need to create a search-bar to find registered users by their name or last name.

I.e. write in the search-bar jose and I want to see Jose Osorio and Jose castro.

I read about create Index in the database but it did not work or I did that wrong, what can i do to solve this?

Upvotes: 7

Views: 6567

Answers (3)

nilsi
nilsi

Reputation: 10761

You can also use rawCollection like this:

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

Upvotes: 12

Jerome Martin
Jerome Martin

Reputation: 239

To add the index :

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

and to make the picker, have a look at : https://atmospherejs.com/fourq/typeahead

Upvotes: 9

MichelH
MichelH

Reputation: 385

You can do it using e.g db.books.createIndex( { "category": 1 } ) from the mongo shell.

Upvotes: 3

Related Questions