Couchbase JAVA SDK -Partialy update document - java

I have a document that has a data model corresponding to a user.
The user has an adresses array, a phone array and an email array.
I make CRUD operations on theses data using the Java SDK for Couchbase.
I have a constraint: I need to get all the document data in order to display data associated to the user. On the UI I can modify everything except the data contained by the arrays (phone, email and adresses).
How can I do to update only those data when I update the document ?
When I try to use the JsonIgnore annotation on arrays method when serializing the user object, it removes them from the document when the JAVA couchbase method replace took place.
Is there a way to update partially documents with the JAVA SDK for couchbase ?

Related

How to get newly updated data only from Firestore?

Always getting whole document while any changes found on Firestore. How to get data that are newly updated only?
This is my data:
I need msg and sendby in order of object(for eg: 2018_09_17_30_40) inside chat on first load and get only the new msg and sendby if data updated
while on get() getting whole document without any order
Note: Code for Android app.
You can store the last fetched date, and only get the objects with date greater than last updated date.
db.collection('groups')
.where('participants', 'array-contains', 'user123')
.where('lastUpdated', '>', lastFetchTimestamp)
.orderBy('lastUpdated', 'desc')
Always getting whole document while any changes found on fire store.
The new Cloud Firestore database has different concepts than Firebase real-time database and should not be confused. There are no field-level permissions or access to a document. It's the entire document, or nothing. Cloud Firestore listeners fire on the document level. There is no way to get triggered with just newly updated data in a document.
Seeing your database, I can say that you haven't chosen the right schema by adding those messages under the chat property.
According to the official documentation:
Cloud Firestore is optimized for storing large collections of small documents.
You should consider create a new collection named messages and store each message as a separate document. In the link above, there are examples of how you can achieve that.

Tokenize textual content using Spark SQL?

I an working on implementing a requirement to create a dictionary of words to documents using apache spark and mongodb.
In my scenario I have a mongo collection in which each document has some text type fields along with a field for owner of the document.
I want to parse the text content in collection docs and create a dictionary which maps words to the document and owner fields. Basically, the key would be a word and value would be _id and owner field.
The idea is to provide auto-suggestions specific to the user when he/she types in the text box in the UI based on the user's documents.
A user can create multiple documents and a word can be in multiple documents but only one user will be able to create a document.
I used mongo spark connector and I am able to load the collection docs into a data frame using spark sql.
I am not sure how to process the textual data which is in one of the dataframe columns now to extract the words.
Is there a way using Spark SQL to process the text content in the data frame column to extract/tokenize words and map it to _id and owner fields and write the results to another collection.
If not, can someone please let me know the right approach/steps on how I can achieve it.
Spark has support for tokenisation and other text processing tasks but it's not in the core library. Checkout the Spark MLlib:
https://spark.apache.org/docs/2.1.0/ml-guide.html
And more precisely the Transformers that work on DataFrames like:
https://spark.apache.org/docs/2.1.0/ml-features.html#tokenizer

Is it Possible to send JSON and store it in Azure Tables with JAVA

I was working on storing a data in azure tables in a meanwhile I found JSON support for Azure tables here. So for a change of plan now I have a data in JSON format i need it to store on azure tables.I found few code snippets but all were for c#. Can you please guide me ?
Thanks in Advance
Azure Table Storage is a Key/Value pair store as opposed to a document store (a good example for that would be DocumentDB). Essentially a table contains entities (broadly think of them as rows) and each entity contains some attributes (broadly think of them as columns). Each attribute consist of 3 things: Attribute name (that would be the key in key/value pair), attribute value (that would the value in key/value pair) and attribute data type.
To answer your question, yes, you can store a JSON document in Azure Tables but that goes in as an attribute thus you need to assign a key to your JSON document. Furthermore each attribute can't be more than 64KB in size so you would need to take that into consideration.
If your requirement is to store JSON documents, I woul recommend looking into DocumentDB. It is more suitable for storing JSON data and doing many more things that Azure Tables can't do.
Regarding your comment about JSON support for Azure table, it talks about the format in which data is sent to/retrieved from Azure tables. In the earlier days, data was transmitted using ATOM PUB XML format which made the request payload/response body really bulky. With JSON format, the size is considerably reduced. However no matter which way you go, Azure Tables store the data in key/value pair format.
#AnandDeshmukh, Based on my understanding, I think you might want to use Java to write the similar code with C#. I suggest that you can try to refer to the javadoc of Azure Storage SDK to rewrite the sample code in Java.
For example, you can use the Java code instead of the C# code as below.
C# code:
CloudTableClient tableClient = new CloudTableClient(baseUri, cred)
{
// Values supported can be AtomPub, Json, JsonFullMetadata or JsonNoMetadata
PayloadFormat = TablePayloadFormat.JsonNoMetadata
};
Java code:
CloudTableClient tableClient = new CloudTableClient(baseUri, cred)
tableClient.getDefaultRequestOptions().setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata);

Storing data(java object) in couchbase

We are converting our, java + MySql application to couchbase, for that we are using spring-data and a couchbase server.
I am confused how the Java objects(Entity / POJO) needs to be saved on to the couchbase bucket.
I read that, i can't create one bucket per Entity, So shall i put all data on to one bucket and add a _class property so that i can identify the data bjects ?
Is that the right way? Please share any links or suggestions about the same.
Spring data with couchbase, This is the link i was using.
if you create objects through Spring Data Couchbase, they will automatically have this _class property. It is use by Spring Data to convert the Json object from Couchbase to a POJO. Using a type field (or the _class field added automatically by Spring Data)is indeed a good practice as it allows you to filter easily when creating views or using N1QL. Which is also how you will find objects of different types in the same bucket.

Android | SQLLite : Pre-created database updating without using SQLiteOpenHelper

My app uses a SQLite database for the information. I have a function that checks to see if the folder and database are already present, if they aren't it will go on the internet ( currently I am using dropbox to store the db file ) and download the database and store it on the sd card, then I it will open the database. The database is writable as it lets the user rate an object. I have two questions.
1.) I would love to provide updates to the database and then have my app update the database if the version number is higher and replace the existing one. I have done some research and from what I have found it is possible to store an xml or json file with the version number of and the just parse the information and if the version number is higher download the new database.
Can someone provide an example of how this is accomplished and whether it is better to use xml or json for this task?
2.) Is there a way to save the rating in the new version of the database when the new is downloaded and accessed?
Thanks
two nights ago I wrote something like that.
pack your database structure as an array in a webservice method by reading field names and field types. the structure of array is arbitrary.
call web service method and you must receive a string that represent a JSONArray object, if you sent it as json with json_encode() method in php.
read structure and make CREATE DB query string with for loops.
execute query, so you must have database.
also you can send alot of information with arrays.
introducing each part is hard, so for each part google it.
don't forget to convert field types to match SQLite types such as VARCHAR=>TEXT, smallint=>INTEGER , ...

Categories

Resources