Wonder to know if mongoexport --queryFile can accept js files? If only json then how can cater this query db.CustomerDocument.aggregate({ $project: { "_id": 1, "Country": 1, "date": { $toDate: "$CustomerOnlineActiveDate" } } })
The following command runs with errors, due to --queryFile value.
mongoexport --uri "mongodb+srv://..." --username myUser --password myPassword --db CustomerDb --collection Customer --fields _id,Country,date --type csv --queryFile c:\test\FromMongo\AccountConversion.json --out c:\test\Mini.csv
In this mongoexport command if I just delete the --queryFile and its assigned path, it works but the case is that I need the following query be executed.
The text in query file is as below. On mongo shell it can be executed with no issues.
db.CustomerDocument.aggregate({
$project: {
"_id": 1,
"Country": 1,
"date": {
$toDate: "$CustomerOnlineActiveDate"
}
}
})
the error I encounter is: []' is not valid JSON: invalid character 'd' looking for beginning of value.
As an alternative to this, I created a .json file with the follwoing content:
{"$project":{"_id":1,"Country":1,"date":{"$toDate":"$CustomerOnlineActiveDate"}}}
and changed accordingly the path to this .json file but still got the following error:
the error I encounter is: []' is not valid JSON: invalid character '\' looking for beginning of object key string.
You are passing a projection where a query filter is expected.
From the docs:
The query filter must be a JSON document, containing query operators.
You might be able to get what you are looking for in 2 steps:
$outstage to store the result in a temporary collection