Skip to content

Instantly share code, notes, and snippets.

@Erliz
Last active March 10, 2016 23:12
Show Gist options
  • Save Erliz/3dc196632e6e141c172e to your computer and use it in GitHub Desktop.
Save Erliz/3dc196632e6e141c172e to your computer and use it in GitHub Desktop.
Creating search collection for subs
db.Anime.aggregate([{$project:{_id: true, title: true, "externalDbs.titles": true, startDate: true, endDate: true}}, {$unwind: "$externalDbs"}, {$unwind: "$externalDbs.titles"}, {$group: {_id: "$_id", titles: {$addToSet: "$title"}, titles: {$addToSet: "$externalDbs.titles"}}}, {$out: "Search"}])
db.Search.find({$text: {$search: 'ajin'}})
// multiple fields https://docs.mongodb.org/manual/tutorial/create-text-index-on-multiple-fields/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment