Home > Back-end >  Using GridFsTemplate, according to the _id read from file, type error, can't find the reason
Using GridFsTemplate, according to the _id read from file, type error, can't find the reason

Time:09-23

 
//take file
@ Test
Public void queryFile () throws IOException {

String a count="5 ec8cea13cc2be46e01a0e65";

/* GridFSFile GridFSFile=this. GridFsTemplate. FindOne (new Query (Criteria) where (" _id ") is (count))); */
GridFSFile GridFSFile=operations. FindOne (new Query (Criteria) where (" _id ") is (count)));
GridFSDownloadStream GridFSDownloadStream=gridFSBucket. OpenDownloadStream (gridFSFile getObjectId ());
GridFsResource GridFsResource=new GridFsResource (gridFSFile gridFSDownloadStream);
The String content=IOUtils. ToString (gridFsResource getInputStream (), "utf-8");
System.out.println(content);



}




 

Org. Bson. BsonInvalidOperationException: the Value expected to be of type DOCUMENT is of unexpected type STRING

The at org. Bson. BsonValue. ThrowIfInvalidType (BsonValue. Java: 419)
The at org. Bson. BsonValue. AsDocument (BsonValue. Java: 47)
The at org. Bson. BsonDocument. GetDocument (BsonDocument. Java: 506)
At com. Mongo. Client. Gridfs. Codecs. GridFSFileCodec. Decode (GridFSFileCodec. Java: 73)
At com. Mongo. Client. Gridfs. Codecs. GridFSFileCodec. Decode (GridFSFileCodec. Java: 48)
At com.mongodb.operation.Com mandResultArrayCodec. Decode (CommandResultArrayCodec. Java: 52)
At com.mongodb.operation.Com mandResultDocumentCodec. ReadValue (CommandResultDocumentCodec. Java: 60)
The at org. Bson. Codecs. BsonDocumentCodec. Decode (BsonDocumentCodec. Java: 84)
The at org. Bson. Codecs. BsonDocumentCodec. Decode (BsonDocumentCodec. Java: 41)
The at org. Bson. Codecs. Configuration. LazyCodec. Decode (LazyCodec. Java: 47)
The at org. Bson. Codecs. BsonDocumentCodec. ReadValue (BsonDocumentCodec. Java: 101)
At com.mongodb.operation.Com mandResultDocumentCodec. ReadValue (CommandResultDocumentCodec. Java: 63)
The at org. Bson. Codecs. BsonDocumentCodec. Decode (BsonDocumentCodec. Java: 84)
The at org. Bson. Codecs. BsonDocumentCodec. Decode (BsonDocumentCodec. Java: 41)
At com. Mongo. Connection. ReplyMessage. & lt; init> (ReplyMessage. Java: 51)
At com. Mongo. Connection. InternalStreamConnection. ReceiveCommandMessageResponse (InternalStreamConnection. Java: 301)
At com. Mongo. Connection. InternalStreamConnection. SendAndReceive (InternalStreamConnection. Java: 255)
At com. Mongo. Connection. UsageTrackingInternalConnection. SendAndReceive (UsageTrackingInternalConnection. Java: 98)
At com. Mongo. Connection. DefaultConnectionPool $a javax.sql.pooledconnection. SendAndReceive (DefaultConnectionPool. Java: 441)
At com.mongodb.connection.Com mandProtocolImpl. Execute (CommandProtocolImpl. Java: 80)
At com. Mongo. Connection. The DefaultServer $DefaultServerProtocolExecutor. Execute (DefaultServer. Java: 189)
At com. Mongo. Connection. DefaultServerConnection. ExecuteProtocol (DefaultServerConnection. Java: 264)
At com.mongodb.connection.DefaultServerConnection.com mand DefaultServerConnection. Java: (126)
At com.mongodb.connection.DefaultServerConnection.com mand DefaultServerConnection. Java: (118)
At com.mongodb.operation.Com mandOperationHelper. ExecuteWrappedCommandProtocol (CommandOperationHelper. Java: 226)
At com.mongodb.operation.Com mandOperationHelper. ExecuteWrappedCommandProtocol (CommandOperationHelper. Java: 217)
At com.mongodb.operation.Com mandOperationHelper. ExecuteWrappedCommandProtocol (CommandOperationHelper. Java: 120)
At com. Mongo. Operation. FindOperation $1. Call (717) FindOperation. Java:
At com. Mongo. Operation. FindOperation $1. Call (711) FindOperation. Java:
At com. Mongo. Operation. OperationHelper. WithConnectionSource (OperationHelper. Java: 471)
At com. Mongo. Operation. OperationHelper. WithConnection (OperationHelper. Java: 415)
At com. Mongo. Operation. FindOperation. Execute (FindOperation. Java: 711)
At com. Mongo. Operation. FindOperation. Execute (FindOperation. Java: 83)
Ats com. Mongo. Mongo $3. The execute (Mongo. Java: 826)
At com. Mongo. FindIterableImpl. First (FindIterableImpl. Java: 193)
At com. Mongo. Client. Gridfs. GridFSFindIterableImpl. First (93) GridFSFindIterableImpl. Java:
At com. Mongo. Client. Gridfs. GridFSFindIterableImpl. First (31) GridFSFindIterableImpl. Java:
The at org. Springframework. Data. The mongo. Gridfs. GridFsTemplate. FindOne (GridFsTemplate. Java: 202)
At com. Xuecheng. Manage_cms. GridFsTest. QueryFile (GridFsTest. Java: 59)
At sun. Reflect. NativeMethodAccessorImpl. Invoke0 (Native Method)
At sun. Reflect. NativeMethodAccessorImpl. Invoke (NativeMethodAccessorImpl. Java: 62)
At sun. Reflect. DelegatingMethodAccessorImpl. Invoke (43) DelegatingMethodAccessorImpl. Java:
The at Java. Lang. Reflect. Method. Invoke (498) Method. The Java:
The at org. Junit. Runners. Model. FrameworkMethod $1. RunReflectiveCall (FrameworkMethod. Java: 50)
The at org. Junit. Internal. Runners. Model. ReflectiveCallable. Run (ReflectiveCallable. Java: 12)
The at org. Junit. Runners. Model. FrameworkMethod. InvokeExplosively (FrameworkMethod. Java: 47)
The at org. Junit. Internal. Runners. Statements. InvokeMethod. Evaluate (InvokeMethod. Java: 17)
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related