Single word search in mongodb

I am new to MongoDB, so I was wondering how you are looking for a document for one word or another, especially if one word is a phrase and the other is one word.

Here, if we need to look for a text printer or ink, we use the syntax below.

db.supplies.runCommand("text", {search:"printer ink"})

What should I do if I want to find the word “printer ink” or paper? Note that printer ink is a phrase. I tried

db.supplies.runCommand("text", {search:"\"printerink\" paper"}) 

but it didn’t help, so I hope someone can help me.

+4
source share
1 answer

Indication of documentation

$search , , . ,

, , printer ink paper,

db.supplies.find({ $text: { $search: "\"printer ink\"" }})

db.supplies.find({ $text: { $search: "paper" }})

$regex , $text

db.supplies.find({ <yourfield>: {"$in": [/printer ink/, /paper/] }})
+3

All Articles