【问题标题】:Meteor js: Create text index in collectionMeteor js:在集合中创建文本索引
【发布时间】:2016-03-19 17:55:39
【问题描述】:

我创建了一个包含名称和描述字段的类别集合。即

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 );

我需要创建一个文本索引来按名称或描述查找类别。 我看到了Meteor js: Create index in user collection,但这不是我的需要,我也试过了

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

我读到了关于在流星中创建索引但它不起作用或者我做错了什么?任何帮助将不胜感激。

【问题讨论】:

    标签: javascript mongodb meteor


    【解决方案1】:

    您使用了错误的 API。

    您应该在您的收藏中致电_ensureIndex

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-08-24
      • 1970-01-01
      • 2015-08-21
      • 1970-01-01
      • 1970-01-01
      • 2015-03-18
      • 2019-04-16
      相关资源
      最近更新 更多