You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm using Spring Boot 3.4.4 with Spring Data MongoDB 4.4.4, and I noticed an issue when using the $out aggregation stage together with .in("new_db"). The aggregation works perfectly if I don't include .in(), meaning it defaults to writing in the current database.
Reproduction
void exportBooksWithPublishedYear() {
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.project("title", "publishedAt")
.andExpression("year(publishedAt)").as("year"),
Aggregation.out("books_year_export")
.in("new_db") // <-- Only breaks when this is included
.mode(OutOperation.OutMode.INSERT)
);
AggregationOptions options = AggregationOptions.builder()
.skipOutput() // <-- I also tried skipOutput but didn't work
.build();
mongoTemplate.aggregate(
aggregation.withOptions(options),
Book.BOOK_COLLECTION_NAME,
Document.class
);
}
Running on MongoDB Atlas 8.0.9 (Cloud) gives:
com.mongodb.MongoCommandException: Command failed with error 8000 (AtlasError): '$out must contain both db and coll'
{
"ok": 0,
"errmsg": "Failed to retrieve database or collection name from $out, err=$out must contain both db and coll",
"code": 8000,
"codeName": "AtlasError"
}
com.mongodb.MongoCommandException: Command failed with error 40415 (IDLUnknownField): 'BSON field '$out.to' is an unknown field.'
{
"ok": 0.0,
"errmsg": "BSON field '$out.to' is an unknown field.",
"code": 40415,
"codeName": "IDLUnknownField"
}
Environment
Spring Boot: 3.4.4
Spring Data MongoDB: 4.4.4
MongoDB Java Driver: 5.2.1
Java: 21
I’m not sure if the $out stage is being constructed correctly under the hood when using .in("dbName"), but it seems to be missing expected fields for the newer MongoDB 8.x versions.
Please let me know if I can help with a sample project or further info. Thanks a lot!
The text was updated successfully, but these errors were encountered:
Hi team,
I'm using Spring Boot 3.4.4 with Spring Data MongoDB 4.4.4, and I noticed an issue when using the $out aggregation stage together with .in("new_db"). The aggregation works perfectly if I don't include .in(), meaning it defaults to writing in the current database.
Reproduction
Running on MongoDB Atlas 8.0.9 (Cloud) gives:
Running on MongoDB AtlasLocalDev 8.0.5 (Docker)
Using the same code on the [MongoDB Atlas Local Docker image] gives:
Environment
I’m not sure if the $out stage is being constructed correctly under the hood when using .in("dbName"), but it seems to be missing expected fields for the newer MongoDB 8.x versions.
Please let me know if I can help with a sample project or further info. Thanks a lot!
The text was updated successfully, but these errors were encountered: