Hi Murthy,
I tried to replicate your problem using a dataset similar to your use case. I am able to export the records using the below command:
mongoexport -d community -c free103901 -q '{inserted:{$lte:ISODate("2016-06-13T06:39:38.115Z")}}' -o ~/Desktop/test1.json
My Sample Dataset:
> db.free103901.find()
{ "_id" : ObjectId("575e54fb381acd5180ca7127"), "name" : "abc", "inserted" : ISODate("2016-06-13T06:38:51.683Z") }
{ "_id" : ObjectId("575e5519381acd5180ca7128"), "name" : "def", "inserted" : ISODate("2016-06-13T06:39:21.810Z") }
{ "_id" : ObjectId("575e552a381acd5180ca7129"), "name" : "ghi", "inserted" : ISODate("2016-06-13T06:39:38.115Z") }
Query Result:
mongoexport -d community -c free103901 -q '{inserted:{$lte:ISODate("2016-06-13T06:39:38.115Z")}}' -o ~/Desktop/test1.json
2016-06-16T11:01:02.328+0530 connected to: localhost
2016-06-16T11:01:02.329+0530 exported 3 records
test1.json
contents:
{"_id":{"$oid":"575e54fb381acd5180ca7127"},"name":"abc","inserted":{"$date":"2016-06-13T06:38:51.683Z"}
{"_id":{"$oid":"575e5519381acd5180ca7128"},"name":"def","inserted":{"$date":"2016-06-13T06:39:21.810Z"}}
{"_id":{"$oid":"575e552a381acd5180ca7129"},"name":"ghi","inserted":{"$date":"2016-06-13T06:39:38.115Z"}}
Please note that you were trying to use mongo
shell syntax with mongoexport command while querying : db.Audit.find(...)
. Instead you just have to provide a JSON
document as a query.
Please see mongoexport for more information on syntaxes and options to use with mongoexport command.
Regards,
Pooja
Hi Murthy,
Apologies for the delay in response. I was out of office for a few weeks.
Could you please try and interchange single and double quotes in the query:
From
mongoexport..... -q '{inserted:{$lte:ISODate("2016-06-13T06:39:38.115Z")}}' -o ......
To
mongoexport..... -q "{inserted:{$lte:ISODate('2016-06-13T06:39:38.115Z')}}" -o ......
This is because, unlike UNIX, windows doesn’t recognise single quotes as delimiter.
Regards,
Pooja