(Mongoose) Get all items in database that have any fields (or all fields) that contain or are similar to search text

Viewed 26

I have some data on books and want to perform a search on these JSON objects:


// all descriptions are from wiki, see footnotes.

{
    title: "In Search of Lost Time",
    author: "Marcel Proust",
    description: "In Search of Lost Time follows the narrator's recollections of childhood and experiences into adulthood in the late 19th century and early 20th century high society France, while reflecting on the loss of time and lack of meaning in the world.", // from wikipedia, see footnotes
    published: "1913" // date
}

{
    title: "Ulysses",
    author: "James Joyce",
    description: "Ulysses chronicles the appointments and encounters of the itinerant Leopold Bloom in Dublin in the course of an ordinary day, 16 June 1904.[4][5] Ulysses is the Latinised name of Odysseus, the hero of Homer's epic poem the Odyssey, and the novel establishes a series of parallels between the poem and the novel, with structural correspondences between the characters and experiences of Bloom and Odysseus, Molly Bloom and Penelope, and Stephen Dedalus and Telemachus, in addition to events and themes of the early 20th-century context of modernism, Dublin, and Ireland's relationship to Britain.", // from wikipedia, see footnotes
    published: "1922" // date
}

Let's say my search text is this: "marcel proust ullyses". I would like both items to be returned from MongoDB.

If, say I were to write "search of time recollections", I would like In Search of Lost time to be the only one that shows up, because in the description it has the word recollections and the title contains the words Search of (lost) Time.

If I had 2 items in the database of "In Search of Lost Time", but one was published 1913 and another was published 1927 and I searched for "In Search of Lost Time 1927" I would expect the latter to be returned. Is this possible?

Thanks

0 Answers
Related