Storing date field from JSON to MongoDB using Java API - mongodb-java

I am using java api for mongodb to parse the JSON string into Java object and storing it into MongoDB.
My JSON string will have fields that are date like the one given below.
"created":"2012-10-17 21:39:06.385987 +0000"
When I try to save the parsed java object into MongoDB it stores the value as String. I would like to store it has a datetime field. Can someone shed some light on this?
Thanks and Regards,
Balaji.R

Java driver, as other default drivers, maps basic language types to MongoDB types, so to save date to mongo, you just need to save the Date object, not date string.
Here's simple sample from MongoDB documentation.

Related

How to get timestamp from date in elastic search script

As the title suggests, I want to get the timestamp (as a number) from a date type in an elastic search painless script. The following attempts didn't work: doc["date_field"].value, doc["date_field"].date.getMillis().
According to the Painless docs you should be able to access the milliseconds since epoch like this: doc.date_field.millis.
Date fields are exposed as ReadableDateTime, so they support methods
like getYear, getDayOfWeek or e.g. getting milliseconds since epoch
with getMillis. To use these in a script, leave out the get prefix and
continue with lowercasing the rest of the method name.
You should also be able to use the methods from ReadableDateTime. https://www.elastic.co/guide/en/elasticsearch/painless/6.4/painless-api-reference.html#painless-api-reference-org-joda-time-ReadableDateTime

Insert UUID data type values in Cassandra Database Using Apache Metamodel

I want to insert UUID type values in Cassandra database using Apache Metamodel. For text data type I am using like
.values("ColName", value)
How can I insert UUID type values?
This SO question says it should look something like
.values(colName, 77820258-ef49-4e61-8a74-debbdd5993ea)
if you have a hardcoded UUID. This gives various ways you can auto-generate a UUID.

Map JSON string property to ES object

I have a process that imports some of the data from external sources to elasticsearch. I use C# and NEST client.
Some of the classes have string properties that contain JSON. Same property may contain different json schema depending on source.
I want to index and analyze json objects in these properties.
I tried object type mapping using [ElasticProperty(Type=FieldType.Object)] but it doesn't seem to help.
What is the right way to index and analyze these strings?
E.g. I import objects like below and then want to query all start events of customer 9876 that have status rejected. I then want to see how they distribute over period of time (using kibana).
var e = new Event (){id=123, source="test-log" input="{type:'START',params:[{name:'customerid',value:'9876'},{name:'region',value:'EU'}]}",result="{status:'rejected'}"};

Difference between serde2.objectinspector and typeinfo packages

What's the difference between these two packages:
org.apache.hadoop.hive.serde2.objectinspector
org.apache.hadoop.hive.serde2.typeinfo
Is one a newer API? Are they both current, but somehow different? They seem pretty similar to me :/
since the two package both under the specifier serde2, i think both of them are in currently use
TypeInfo stores information of a type, and each type with exactly one object to represent it. so, TypeInfo is just a read-only information deal with the object's type(category, type name, etc)
Hive has multiple in-memory data format for a given type (e.g. Integer: Integer, IntWritable and LazyInteger). data are stored in object and format/operations stored in object inspector. so a data object and objectinspector represents a data unit, feels like you can deserialize the object use the information provided by objectinspector.
ObjectInspectors are used to serialize an object, like suppose you are creating a JSON serde and using a JSON library to convert java objects into JSON and vice versa, then the Hive object you receive is an internal representation of row, this needs to be converted to java object which will be further converted to JSON. for the Hive to JAVA conversion we need objectInspectors eg ListObjectInspector.
Similarly when you deserialize you convert a JSON to a Hive row object, for that we use TypeInfo class eg ListTypeInfo.

Store _Id as object or string in MongoDB?

I am developing an API using Codeigniter and MongoDB.
In this system I am saving the full name and _ID of users that the selected user
is following.
What is best to do regarding the _Id? Store it as an object or as a string?
If I store it as an object I need to convert it to string when echoing out followers otherwise
the output looks strange.
My question is really. Is it ok to store the _Id as a string rather than an object?
What is the downside of storing as string?
Thankful for all input!
Performance for requests (and updates) are really better with objectid. More over, objectid are quite small in space.
From the official doc :
BSON includes a binary data datatype for storing byte arrays. Using
this will make the id values, and their respective keys in the _id
index, twice as small.
here are 2 links that can help you :
- http://www.mongodb.org/display/DOCS/Optimizing+Object+IDs
- http://www.mongodb.org/display/DOCS/Object+IDs
When you use ObjectId, it generates _id as a unique value in all your computers. So if you use Sharding, you will not worry about you _id conflicts. See how ObjectId generates in specification
But if you use string, you should generate it carefully.

Resources