Implementing MongoDB 2.4's full text search in a Meteor app

后端 未结 2 1518
暗喜
暗喜 2021-01-30 13:40

I\'m looking into adding full text search to a Meteor app. I know MongoDB now supports this feature, but I have a few questions about the implementation:

  • What\'s t
2条回答
  •  醉酒成梦
    2021-01-30 14:05

    To create a text index and try to add like this I hope so it will be useful if there is still problem comment

    From docs.mongodb.org:


    Append scalar index fields to a text index, as in the following example which specifies an ascending index key on username:

    db.collection.ensureIndex( { comments: "text",
                                 username: 1 } )
    

    Warning You cannot include multi-key index field or geospatial index field.

    Use the project option in the text to return only the fields in the index, as in the following:

    db.quotes.runCommand( "text", { search: "tomorrow",
                                    project: { username: 1,
                                               _id: 0
                                             }
                                  }
                        )
    

    Note: By default, the _id field is included in the result set. Since the example index did not include the _id field, you must explicitly exclude the field in the project document.

提交回复
热议问题