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?
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
}
});
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
You can do it using e.g db.books.createIndex( { "category": 1 } )
from the mongo shell.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With