Mongo reader Malfunction reading objectId of a record

Hi CloverETL Team,

I need to read object id values and obviously some other fields of all records in my collection.But i found a faulty operation of mongo reader.At times it gives out the actual integer value of object and in other graphs found returning using $oid{} format.
For example if my record is as follows:
{
“_id” : ObjectId(“53b0e85472a0ec06118b45ff”),
“category” : “Part”
}
In output mapping of mongo reader i use source code $out.0.product_id = $in.1.jsonObject[‘_id’] .
But graph reader components product_id value is 53b0e85472a0ec06118b45ff and for some graph product_id value is {“$oid”:“53b0e85472a0ec06118b45ff”}.
My requirement is the first case that’s the actual value (53b0e85472a0ec06118b45ff) without $oid . I’m really interested to know how to acquire both conditions.

Thanks in advance,

Hi sidharth,

Can you please check that your database really contains only ObjectId as _id? Because Mongo accepts as _id any data type. So it is well possible you have string “ObjectId(\“53b0e85472a0ec06118b45ff\”)” used as _id. Or even object {“$oid”:“53b0e85472a0ec06118b45ff”}. In that case you would need to dive into that object - so not only by “_id” but also “$oid”.

You can check what _id values you have by Mongo viewer like RoboMongo. In case you won’t be able to detect problem please send us screenshot of two expanded records - one which return correct _id and one which does not.

I hope this helps.

The object id is present as “_id” : ObjectId(“53b0e85472a0ec06118b45ff”).
I need to get value 53b0e85472a0ec06118b45ff in metadata product_id ,is it possible in output mapping of mongo reader to do the necessary adjustments.How do you suggest We dive into that object and take the value?

Hi sidharth,

Diving into _id/$oid is not possible in MongoReader, there is available only one root key-value map. For that you need to pass whole JSON object text into JSONReader/Extract and extract value there. Sample mapping for JSONExtract may look like:


<Mappings>
	<Mapping element="json_object">
		<Mapping element="_id">
			<Mapping element="_x0024oid" outPort="0"
					xmlFields="../{}_x0024oid"
					cloverFields="_id">
			</Mapping>
		</Mapping>
	</Mapping>
</Mappings>

(x0024 is escape for $)

I hope this helps.