Open arisnegro opened 1 year ago
Will investigate... Can you provide an example of an export of mongoDB dataset that uses DB_POINTER type?
Hi!!
The example is there:
"fieldDbPointer": { "$$DB_POINTER": { "namespace": "categories", "objectId": "5db7545b7b615c739732c773" }}
:) :)
For example, you can use a data set file like this one:
[ { "collectionName" : "categories", "documents" : [ { "name" : "Category_1", "_id" : { "$$OBJECT_ID" : "5db7545b7b615c739732c773" } }, { "name" : "Category_2", "_id" : { "$$OBJECT_ID" : "5db7545b7b615c739732c774" } } ] }, { "collectionName" : "items", "documents" : [ { "name" : "Item 2", "_id" : 2 }, { "name" : "Item 1", "_id" : 1, "fieldDbPointer": { "$$DB_POINTER": { "namespace": "categories", "objectId": "5db7545b7b615c739732c773" }} } ] } ]
If you use this file to feed and assert the database, you will get this exception:
org.bson.BsonInvalidOperationException: Value expected to be of type OBJECT_ID is of unexpected type DB_POINTER at org.bson.BsonValue.throwIfInvalidType(BsonValue.java:419) at org.bson.BsonValue.asObjectId(BsonValue.java:150) at org.mongounit.MongoUnitUtil.getFieldValue(MongoUnitUtil.java:493) at org.mongounit.MongoUnitUtil.getDocument(MongoUnitUtil.java:331) at org.mongounit.MongoUnitUtil.getMongoUnitDocuments(MongoUnitUtil.java:302) at org.mongounit.MongoUnitUtil.fromDatabase(MongoUnitUtil.java:118)
The problem could be in the method org.mongounit.MongoUnitUtil#getFieldValue:
... case DB_POINTER: String namespace = bsonValue.asDBPointer().getNamespace(); String objectId = bsonValue.asObjectId().getValue().toHexString(); MapdbPointerValueMap = new HashMap<>(); dbPointerValueMap.put("namespace", namespace); ...
The invocation bsonValue.asObjectId()
seems to not be valid.
Hi!
When the expected value is a DB_POINTER, MongoUnit fails loading the dataset.
Expected data:
"fieldDbPointer": { "$$DB_POINTER": { "namespace": "categories", "objectId": "5db7545b7b615c739732c773" }}
Error: org.bson.BsonInvalidOperationException: Value expected to be of type OBJECT_ID is of unexpected type DB_POINTER
Bye!!