Thank you @ldoguin for the reply. I know this N1qlQuery but I wan to write it using
bucket.query(N1qlQuery.simple(
** “INSERT INTO default(KEY, VALUE) values(“jsonStrnig”);**”));
So that I can write in my Java program while communicating to the Couchbase
@pioneer.suri the question is: why do you want to use N1QL to insert records and not use the regular KV mutation APIs? if its just a plain insert you can do bucket.insert, upsert or replace.
Any specific example so we can help you figure it out?
but the document is stored as shown above the attached image:
So I am not able to retrieve required json nodes from the documents.
That’s the reason I wanted to insert in different way(N1ql) instead of using Mutation API.
Please help me to solve this Issue. Let me know If you need any more details.
Yeah your device is not a json object but actually a Json string! can you copy the full code you are using to insert the document? I think I can spot the issue then probably pretty quickly.
Note that this will not put it into “info” since you are nesting. Alternatively if you want to make it work like this, even if its a little more wasteful on the GC side you could do
Fetching the data from the bucket, It is giving the following result.
select * from default USE KEYS[“device1”];
Result:
[
{
“default”: “<binary (24543 b)>”
}
]
May I know In which Scenario it is preferable, because We are not getting the data in the required format.
So I have used the following JSONObject to create JSONDocument.
JsonObject infoObj = JsonObject.create().put(“info”, JsonObject.fromJson(finalData));
Now it is working as per my expectation. but You are saying It will waste on GC side. Is it meant, Performance will differ comapre to binary format.
In your example above you store the document as “device” key but query “device1”, that’s why its not returned I guess?
if you use the RawJsonDocument and pass in a valid json string as the document value it will be stored as proper JSON on the server side, many users are doing that. In your case it depends on what you’d like to do, if you get the raw json already it makes sense to store it directly. In the other case if you want to make some modifications to it converting it into an actual object gives you more flexibility.