Hello, I am very new to MongoDB. google this mongoexport syntax but couldn’t get it work on powershell. Not sure what I did wrong. thanks in advance. My server is windows 2016 , powershell 5.1.
mongoexport --collection=<collection_name> --db=<db_name> --out=D:\out.json --query= ‘{“createdAt”: {"$lt": {"$date": new Date(1597261765739)}}}’
I got this error “too many positional arguments: [{ createdAt: {: {: new Date(1597261765)}}}]”.
I also tried
‘{“createdAt”: {"$lt": {"$date": “2020-02-28T00:00:00.000Z”}}}’ and
“{“createdAt”:{”$gte": new Date(1597261765739}}}"… they all end up with same error
The createdAt has value like this in the collection
“createdAt” : ISODate(“2020-04-13T23:01:01.560+0000”)
Thanks for the reply. I made some progress. look like previous error is due to the character of the quote. error from copy/paste. After modify it, it executed but 0 records returned. I tried:
–query="{‘createdAt’: {’$lt’: {’$date’: ‘2020-08-13T23:01:01.560+0000’}}}"
–query="{‘createdAt’: {’$lt’: {’$date’: ‘2020-07-28T00:00:00.000Z’}}}"
–query="{‘createdAt’: {’$lt’: {’$date’: new Date(1597261765739)}}}"
msg:
ok, finally. I made some progress. It is the problem with my Powershell code. I tested the mongoexport with command prompt with --query="{‘createdAt’: {’$lt’: {’$date’: ‘2020-08-13T23:01:01.560+0000’}}}", the collection was successful exported.
I will work on the powershell script. thank you for your help.