Is ISODate or new Date supported by MongoDB + Matlab?

2 ビュー (過去 30 日間)
Victor Hernandez
Victor Hernandez 2021 年 8 月 5 日
回答済み: Peter 2024 年 11 月 20 日
Ive been trying to do a query based on a date field and the existence of a field. My query is as follows
$and:[
{"timestamp":{$lt:ISODate("2022-10-11")}},
{XtsMover_9_ActAcc:{$exists:true}}
]
This query runs fine in mongoDB compass but it does not work when I try to run the query from Matlab. ISODate or New Date supported by Matlab?
This is what I get from matlab:
Error using mongo/find (line 797)
[Mongo Driver Error]:
{$and:[{"timestamp":{$lt: ISODate("2022-10-11")}},{"XtsMover_9_ActAcc":{$exists:true}}]}
^.
Thabks for the help
  4 件のコメント
xiang zhang
xiang zhang 2021 年 9 月 15 日
Hi Victor, i have run into the same program. So far i can't do query based on date in mongo through matlab. Any update on this issue? Thanks a lot...
Victor Hernandez
Victor Hernandez 2021 年 10 月 4 日
Hi Xiang. I am so sorry for the very very very late reply. No updates from my side I am afraid.
What I ended up doing was to create some sort of time stamp to be able to perform date queries without having to explicitly use ISODate from Matlab

サインインしてコメントする。

回答 (1 件)

Peter
Peter 2024 年 11 月 20 日
After hours of messing with queries in MATLAB, I was able to find a solution to this issue.
The following code allows you to query with a date. The format the MATLAB interpreter accepts is not the same as MongoDB.
This format worked for me, even though in MongoDB Compass the same style of query is incorrect.
mongoDB = mongoc(server,port,dbname);
query = "{ ""FirstSeen"": { ""$gte"": {""$date"": ""2024-05-12T15:04:20.803Z""}} }";
find(mongoDB, collection, Query=query)

Community Treasure Hunt

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

Start Hunting!

Translated by