Meteor js: creating a text index in a collection

I created a collection of categories with a name and description field. i.e

Categories = new Meteor.Collection('categories');

CategoriesSchema = new SimpleSchema({
    translation:{
        type: [Object]
    },
    "translation.$": {
        type: Object
    },
    "translation.$.name": {
        type: String
    },
    "translation.$.description": {
        type: String
    }
});

Categories.attachSchema( CategoriesSchema );

I need to create a text index to find categories by name or description. I saw Meteor js: create an index in a custom collection , but this is not about my need, I also tried

Meteor.startup(function () {
    Categories._createIndex(
        { 'translation.$.name' : "text" },
        { 'translation.$.description' : "text" },
        { default_language: "english" }
    );
});

I read about creating an Index in a meteor, but it didn’t work, or did I do it wrong? Any help would be appreciated.

+4
source share
1 answer

You are using the wrong API.

You must call _ensureIndexin your collection.

+1
source

All Articles