How to search text in MongoDB
Afficher commentaires plus anciens
MongoDB allows you search for a word in the database
db.articles.find( { $text: { $search: "coffee" } } )
There doesn't seem to be an equivalent in matlab's interface to MongoDB.
Any thoughts on how to search for a string in the database?
Réponses (1)
Nipun Katyal
le 3 Mar 2020
Make sure you have a proper installation of MongoDB and the corresponding support packages in matlab
To connect to an existing database here is the link to the documentation
To connect to an existing database
server = "dbtb01";
port = 27017;
dbname = "mongotest";
conn = mongo(server,port,dbname)
To execute a search query
collection = "employee";
mongoquery = '{"department":"Sales"}';
documents = find(conn,collection,'Query',mongoquery);
4 commentaires
Thomas Dufresne
le 3 Mar 2020
Modifié(e) : Image Analyst
le 3 Mar 2020
Nipun Katyal
le 4 Mar 2020
One way is to extract a collection from the database which is stored as a structure.
collection = "articles";
documents = find(conn,collection);
To search for a string in a structure we can use structfun as given in the link
Thomas Dufresne
le 6 Mar 2020
Ralf Elsas
le 7 Avr 2020
Modifié(e) : Ralf Elsas
le 7 Avr 2020
Hi, I was just bothering with the same problem.
A solution I have found is to use the $regex command in the find function:
mongoquery = '{"label": {$regex: "pay"}}'
finds all documents where the text variable "label" contains "pay", using find(conn,collection,'Query',mongoquery).
Hope this helps.
Catégories
En savoir plus sur Database Toolbox dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!