[JAVA-3777] Driver 3.11.x - $out fails with Value expected to be of type STRING is of unexpected type DOCUMENT Created: 08/Jul/20  Updated: 27/Oct/23  Resolved: 11/Jul/20

Status: Closed
Project: Java Driver
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Ralph Capasso Assignee: Jeffrey Yemin
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified


 Description   

Code to re-create the issue:

 public void writeDataToAtlasCluster(
      final String pMongoUri,
  final String pDataLakeCollection,
  final String pDataLakeDatabase,
  final String pAtlasCollectionName,
  final String pAtlasDatabaseName,
  final String pClusterName) {
    final MongoClient mongoClient = new MongoClient(new MongoClientURI((pMongoUri)));
    mongoClient
        .getDatabase(pDataLakeDatabase)
        .getCollection(pDataLakeCollection)
        .aggregate(
            List.of(
                new Document()
                    .append(
                        "$out",
                        new Document(
                            "atlas",
                            new Document()
                                .append("clusterName", pClusterName)
                                .append("db", pAtlasDatabaseName)
                                .append("coll", pAtlasCollectionName))))).toCollection();
  }

Resulting Error:

Exception in thread "main" org.bson.BsonInvalidOperationException: Value expected to be of type STRING is of unexpected type DOCUMENT
	at org.bson.BsonValue.throwIfInvalidType(BsonValue.java:419)
	at org.bson.BsonValue.asString(BsonValue.java:69)
	at org.bson.BsonDocument.getString(BsonDocument.java:234)
	at com.mongodb.client.internal.AggregateIterableImpl.getOutNamespace(AggregateIterableImpl.java:188)
	at com.mongodb.client.internal.AggregateIterableImpl.toCollection(AggregateIterableImpl.java:93)
	at TestAdlJava.writeDataToAtlasCluster(TestAdlJava.java:28)
	at TestAdlJava.main(TestAdlJava.java:40)



 Comments   
Comment by Ralph Capasso [ 10/Jul/20 ]

jeff.yemin, should I close this ticket?

Comment by Ralph Capasso [ 10/Jul/20 ]

jeff.yemin, thanks for the follow-up. We are currently working around this for our purposes by using runCommand. We can switch back to the Java driver when Atlas gets to 4.1.x.

Comment by Jeffrey Yemin [ 10/Jul/20 ]

We generally don't add support for new features in patch releases, so I think you will have to use the 4.1 driver for this. 4.1.0-rc0 has been released today.

Generated at Thu Feb 08 09:00:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.