Multiple IDs for the same Query in MongoDB

조회 수: 16 (최근 30일)
Philippe Walliser
Philippe Walliser 2019년 5월 29일
답변: Guillaume 2019년 5월 29일
I am querying a remote MongoDB database with Matlab.
I have an array of IDs that I would like to look for and a query tipically looks like this:
query520 = sprintf('{"_ref":{$oid:"%s"}, "eventTypeId":520}', IDs{end});
Is their a way to check multiple (selected) IDs at once like this:
query520 = sprintf('{"_ref":{$oid:"%s"}, "eventTypeId":520}', IDs{1:2});
Thanks for our help and time!

답변 (1개)

Guillaume
Guillaume 2019년 5월 29일
Seems more like a question on how to write MongoDB queries rather than about matlab. Going by the documentation there and there, probably:
query520 = sprintf('{"_ref":{$in:[%s]}, "eventTypeId":520}', strjoin(compose('{$oid:"%s"}', string(IDs(1:2))), ','));

카테고리

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

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by