How to search text in MongoDB

조회 수: 4 (최근 30일)
Thomas Dufresne
Thomas Dufresne 2020년 2월 27일
편집: Ralf Elsas 2020년 4월 7일
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?

답변 (1개)

Nipun Katyal
Nipun Katyal 2020년 3월 3일
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
Thomas Dufresne
Thomas Dufresne 2020년 3월 6일
Thanks for your response. I was hoping to find a way that can actually search the database first for the occurrence of a text string, as opposed to pulling everything into matlab and then searching for a text string within a structure. It appears that MongoDB can search for a string within the database, but that not feature is not available in the matlab implementation.
Ralf Elsas
Ralf Elsas 2020년 4월 7일
편집: Ralf Elsas 2020년 4월 7일
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.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Database Toolbox에 대해 자세히 알아보기

제품


릴리스

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by