Just a quick question I hope someone can answer for me.
I have a collection in MongoDB containing 84 thousand documents. The data looks something like this:
There are several thousand documents containing the word "BOND" as the category name such as this:
And many thousands more...
Currently in MongoDB Compass I am using the following query:
{ "Category" : "BOND" }
But of course this just returns 1 document that where the Category is BOND.
Can anybody tell me how I can query to find all documents where the field name "Category" contains the word "BOND" within it?
Many thanks, G
You can type MongoDB filter documents into the query bar to display only documents which match the specified criteria. To learn more about querying documents, see Query Documents in the MongoDB manual.
The find() Method To query data from MongoDB collection, you need to use MongoDB's find() method.
The query operators enhance the functionality of MongoDB by allowing developers to create complex queries to interact with data sets that match their applications. MongoDB offers the following query operator types: Comparison. Logical.
You should use regexp for this, i.e.
{ "Category" : /^BOND.*/ }
for categories begins with BOND, or
{ "Category" : /.*BOND.*/ }
for categories contains BOND within
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With