Im running the current Mongo query and getting this error: { "message" : "$out stage requires a string argument, but found object", "operationTime" : "Timestamp(1634539335, 2)", "ok" : 0, "code" : 14, "codeName" : "TypeMismatch", "$clusterTime" : { "clusterTime" : "Timestamp(1634539335, 2)", "signature" : { "hash" : "sP5j8mWdcjkUzZ3iHkg3obPhjMw=", "keyId" : "6985187295267651587" } }, "name" : "MongoError" }
I used this code for earlier copy to other s3 bucket and didn't had problem.
Does anyone see what is the problem?
var startDate = ISODate("2021-04-10");
var endDate = ISODate("2021-04-11");
var currDate = ISODate()
publishersId.forEach(publisherId =>
{
for (var d = startDate; d <= endDate; d.setDate(d.getDate() 1)) {
print(publisherId "_" d);
db.direct_client_extended_alerts_dl.aggregate([
{
"$match":
{ "publisher_id":publisherId,"created_date": d}
},
{
"$out":
{
"s3": {
"bucket": "mongo-datalake-prod",
"filename": {
"$concat": [
"direct_client_extended_alerts/", {"$toString": "$publisher_id"}, "/",
{"$toString": "$created_date"}, "/",
{"$toString":currDate},"/"
]
}
}
}
}
],{ allowDiskUse: true })
}
}```
CodePudding user response:
According to the official documentation of $out
:
Starting in MongoDB 4.4, you can specify the output database.
As you said you are using MongoDB 4.2, the feature is not yet supported. You may either consider:
- upgrading your MongoDB
- try to use $merge and see if it helps
- using other method to export the data.
CodePudding user response:
Found the problem, I was running the query from my PROD DB and not from my DATALAKE PROD DB. Once I changed it to DATALAKE DB it runs.