Write empty strings to MongoDB Output - Pentaho - mongodb

when I try to write some values into my mongodb output in Pentaho, I would like null values of string fields to be translated to empty strings. Instead the key itself is not appearing in the mongo database. For example, if my field 'name' has a null value or a missing value, then I would like 'name':'' to appear in my mongo collection. Can anyone help me with this issue ?

Use the If field value is null step to convert null values to empty strings. To actually store the empty string in mongo set KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL in kettle.properties
KETTLE_EMPTY_STRING_DIFFERS_FROM_NULL=Y
Another solution is to create a schema in mongo, to have default values, like #zydcom says in the comments.

Related

MongoDb database Filter is not working in Compass

When I query all the records, i get the results as shown below.
When i copy an ID from the result and add it in the filter, no result is found.
Here is the example filter from documentation
What am i doing wrong? mongo db got to be kidding me :/
You are not providing the data type with the query. Since your _id field is ObjectId type and you are comparing as string that is why it is not working.
Change your filter condition and convert your string id to ObjectId type.
{_id: ObjectId('yourId')}
MongoDB provides an automatic unique identifier for the _id field in the form of an ObjectId data type.

Mongo db : data uploaded using CSV has Null stored as String in Mongo document

I tried uploading data into Mongodb using CSV from Mongodb Compass. In the CSV, some of the fields have Null values stored in them. But, after uploading those fields in Mongo, documents have "Null" stored as String. Is there a way to store Null fields from CSV with the type Null?
You can correct easily later:
db.contacts.update({a:"Null"}, {$set: {a: null}},{multi:true} )
or you can remove those fields from the document:
db.contacts.update({a:"Null"}, {$unset: {a:1}},{multi:true} )
I couldn't find a solution to import the data with NULL values using CSV and have them stored with datatype NULL in Mongodb. Then I imported the same data using JSON and it worked!! Importing data using JSON makes it to interpret NULL as NULL datatype, not as string.

Mongo distinct query returns several records one of which is "". But find null fails to find it

I ran a distinct query on a collection. The query syntax:
db.Collection.distinct("dict.field")
I got a set of results - one of which was "" (null).
I then tried to find the record that had a null value for the field in question:
db.Collection.find({"dict.field": null})
To my surprise, no record was found.
No indexes are set on this collection other than _id.
The field in question is a dictionary.
What am I missing?
You should look for db.Collection.find({"dict.field": ""}) instead. Null and String ("") are considered different datatypes.
https://docs.mongodb.com/manual/reference/bson-types/

How to retrieve all values from a column in mongoDB

I am wondering how to retrieve all values stored in a column in mongoDB, and put them in a list. find() only get all the fields, and specify <field>: <value> isn't an option as well.
If you are expecting to retrieve unique values in a column then distinct should work for you. Following is the syntax :
db.yourcollection.distinct("yourfield");
Learn more about distinct here

Convert string to Mongo ObjectID in Javascript (Meteor)

I have a Meteor application whereby I initially use the _id field from each record in my collection when naming list items in my template.
When get the _id field, I convert it to a string to use in the template.
Now I want to update these records in Mongo and am passing the _id back to a Meteor.method, but these are still in string format and Mongo is expecting an ObjectID(). Is there a simple way to convert this string to the ObjectID()? If not, what alternatives do I have?
Ok, found it! On the /server, within your Meteor method function do this to convert it:
var mid = new Mongo.ObjectID(str_id_sent_to_server);