Saturday 15 January 2011

indexing - How to read multikey index values in MongoDB? -


I have the autocomplete feature that suggests from the keyword database is . If I use mangodibi and multi indexes , then I have already found these keywords in the database, but can I use them in some way?

If I have an object in the collection: <"> something", "awesome", "title"]}

and I have: "Some awesome titles", "Keyword" Multique index:

  db.somecollection.ensureIndex ({"keyword": 1})   

So in the index The following values ​​will be:

  "some" "horrible" title "  

If the user enters" s "in full control under" self " The app should suggest "some" keywords. Can I suggest index Can I search keywords or how should I do this?

You can choose to use the aggregation framework :

  DEV: History: PRI> Db.test.find () {"_id": ObjectId ("51c37c0c20d107378f9af3cc"), "Title": "Some Awesome Titles", "Keywords ":" Something awesome "," title "]} {" _id ("51c37de420d107378f9af3ce"), "title": "some awesome title", "keyword": ["something", "wonderful", "something "" "{" _id "}: ObjectId (" 51c37f1920d107378f9af3cf ")," title ":" some awesome title "," keyword ": [" something "," awful "," some "]} DEV: Hits: PRI & gt; Db.test.aggregate ({$ match: {keywords: / ^ som}}, {$ project: {keywords: 1, _id: 0}}, {$ unwind: "$ keyword"}, {$ match: {keywords : / ^ Mon}}, {$ Group: {_id: 'keyword', count: {$ sum: 1}}}} {"result": [{"_id": "any", "count": 1 }, "OK": {"_id"}: "something", "count": 2}, {"_id": "something", "count": 2}]: 1}   

Note: The multi-index index is not covered and some JIRA issues have already been filed. Therefore, despite using indexed questions have not been included (for multi-main indexes)

We alternatively use the 'count' parameter to decide in order of auto-complete Can do for If you do not need it, remove from the query.

No comments:

Post a Comment