bson文件的size()函数返回的int值是多少字节? (无法找到此API的详细信息。)
如何以字节为单位获取bson文档的大小?这是我的代码。
import org.bson.Document;
MongoDatabase db...;
MongoCollection<Document> mongoCollection = db.getCollection(...);
MongoCursor<Document> cursor = mongoCollection.find().iterator();
Document doc = cursor.next();
int size = doc.size(); // does this return number of bytes
// how to get size of doc in bytes?
答案 0 :(得分:0)
以RawBsonDocument
格式获取文档,然后使用getByteBuffer().remaining()
方法。
MongoCollection<RawBsonDocument> mongoCollection = db.getCollection(collectionName, RawBsonDocument.class);
MongoCursor<RawBsonDocument> cursor = mongoCollection.find().iterator();
RawBsonDocument doc = cursor.next();
int size = doc.getByteBuffer().remaining()