
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
tMongoDBOutput - getting null array when value is null
I'm writing to MongoDB - using the tMongoDBOutput using the generate JSON Document option. I'm doing a Set action to fill in addresses.
Input fields (all are string)
address1
address2
city
state
The target collection has a unique integer value CustomerID which is used for the "query".
Under the document there is
rootTag
data
CustomerID
addresses (@class array)
row5 (object, loop element)
address1
address2
city
state
with the obvious mapping.
This works fine... except when address2 is null ... I get the address2 output in Mongo as an 0 element array! The advanced option "create empty element if needed" is not checked.
What I want is either address2 being an empty string, or not having an address2 element if there is no address2 data. I tried in a tMap to convert null to "", but got the same result.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
For testing purpose, could you please add single space " " and see whether it is resolving the issue?
Warm Regards,
Nikhil Thampi
Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Using the tMap to convert address2 to " " if null, the result in Mongo is now a string address2 and the content is a single space.
This is better than before, but I'd still prefer the field to be suppressed.
I'm on Talend Open Studio Big Data 7.1.1
Thanks!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Could you please check whether you have selected "Remove Null Field" option in the mapping for tMongoDBOutput? If its checked, could you please uncheck it and try again?
Warm Regards,
Nikhil Thampi
Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I'm not sure where you see "Remove Null Field" in tMongoDBOutput. I see "create empty element if needed" and that is NOT checked.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Could you please select it and see whether data is getting created for empty elements?
Warm Regards,
Nikhil Thampi
Please appreciate our Talend community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Turning on or off the setting "create empty element if needed" seems to make no difference. Results are the same either way.
I wonder if the logic for creating (or not) is getting applied at the "row5" level, because that is an object? So if there's anything for the object, the entire object is created, including address2.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am also facing this issue. Did you find solution to this?
