Mongoexport with query time in milliseconds

Hello Experts,

I have the following database and i am trying to export records from it at 15 mins interval.

db.nodeLatestStatus.aggregate( [
… { “$match” : { “nodeName” : “nodexxx”, “type” : “eNodeB” } },
… {“$sort” : {“time” : 1}},
… { “$project” : {“_id” : 0, “nodeName” : 1,“time” : 1,“type”: 1 } }
… ] )
{ “nodeName” : “nodexxx”, “type” : “eNodeB”, “time” : ISODate(“2023-05-22T11:51:28.686Z”) }
{ “nodeName” : “nodexxx”, “type” : “eNodeB”, “time” : ISODate(“2023-05-22T11:51:28.686Z”) }
{ “nodeName” : “nodexxx”, “type” : “eNodeB”, “time” : ISODate(“2023-05-22T11:51:28.686Z”) }
{ “nodeName” : “nodexxx”, “type” : “eNodeB”, “time” : ISODate(“2023-05-22T11:51:28.686Z”) }
{ “nodeName” : “nodexxx”, “type” : “eNodeB”, “time” : ISODate(“2023-05-22T11:51:28.686Z”) }
{ “nodeName” : “nodexxx”, “type” : “eNodeB”, “time” : ISODate(“2023-05-22T11:51:28.686Z”) }
{ “nodeName” : “nodexxx”, “type” : “eNodeB”, “time” : ISODate(“2023-05-22T11:51:28.686Z”) }
{ “nodeName” : “nodexxx”, “type” : “eNodeB”, “time” : ISODate(“2023-05-22T11:51:28.686Z”) }
Type “it” for more

My python code is constructing the below command , however i get 0 records from it.

mongoexport --host=xx.xx.xx.xx --port=27017 --db=test_nodedata --collection=nodeLatestStatus --query=‘{ “time” : { “$gte” : { “$date” : “2023-05-22T11:45:00Z” },“$lte” : { “$date” : “2023-05-22T11:59:59Z” } } }’

node:database> mongoexport --host=xx.xx.xx.xx --port=27017 --db=test_nodedata --collection=nodeLatestStatus --query=‘{ “time” : { “$gte” : { “$date” : “2023-05-22T11:45:00Z” },“$lte” : { “$date” : “2023-05-22T11:59:59Z” } } }’
2023-05-22T16:59:43.654+0200 connected to: mongodb://xx.xx.xx.xx:27017/
2023-05-22T16:59:43.710+0200 exported 0 records

I also tried with the below format but no records.

mongoexport --host=xx.xx.xx.xx --port=27017 --db=test_nodedata --collection=nodeLatestStatus --query=‘{ “time” : { “$gte” : { “$date” : “2023-05-22T11:45:00.000Z” },“$lte” : { “$date” : “2023-05-22T11:59:59.999Z” } } }’

node:database> mongoexport --host=xx.xx.xx.xx --port=27017 --db=test_nodedata --collection=nodeLatestStatus --query=‘{ “time” : { “$gte” : { “$date” : “2023-05-22T11:45:00.000Z” },“$lte” : { “$date” : “2023-05-22T11:59:59.999Z” } } }’
2023-05-22T16:59:43.654+0200 connected to: mongodb://xx.xx.xx.xx:27017/
2023-05-22T16:59:43.710+0200 exported 0 records

Thanks!!

Hi @Shashikant_Saxena welcome back to the community!

It’s been some time since you posted this. Have you managed to do this?

If not, my question is, what happens when you try to execute the query you’re using in mongoexport, i.e.

db.nodeLatestStatus.find({ "time" : { "$gte" : { "$date" : "2023-05-22T11:45:00Z" },"$lte" : { "$date" : "023-05-22T11:59:59Z" } } })

do you see any documents? I’m suspecting that the query you used actually didn’t match any documents.

Best regards
Kevin

Hi @kevinadi !! many thanks for reply.

You are absolutely right. find() doesn’t return any result as you expected and it is due to the fact that the data stored is in format YYYY-MM-DDTHH:MM:SS.sssZ format.
In the same DB there are collections where data is stored in format YYYY-MM-DDTHH:MM:SSZ and for those monogexport and find () works well.

Regards,
Shashi