Problem with Document ID and INSERT on N1QL?


#1

Hi,
I have been using Couchbase Mobile for iOS App. I used Sync Gateway for replication of data. Now i want to build a Web Admin on Web Browser to access and create data on Couchbase. Now Application working good with Couchbase Mobile for iOS App.

I decided to use N1QL REST API to do CRUD operations on Web Browser. i’m able to fetch data from Server by using N1QL query.

Now its time to insert new users data into couchbase server and it mush work with Couchbase Sync Gateway.

I used following N1QL query. but here i’m wonder why to mention document name, because its taking as a Document Id. When i work with Sync Gateway. i didn’t mention any key for Document Creation. So how to insert a new document into Couchbase without any manual Document name as like SyncGateway.

INSERT INTO default (KEY, VALUE) VALUES (“odwalla-juice3321”, { “productId”: “odwalla-juice123”, “unitPrice”: 4.40, “type”: “produc2t2”, “color”:“red”})

  1. How to find out Document ID on following query.

select * from default

Because some times. i can use result document ID to fetch other documents. Now data looks like below.


#2

You can do:

SELECT *, META(d).id FROM default d;


#3

@geraldss So nice. hey what about sync gateway.

1 does N1QL was created documents replicated with synch gateway?
2. How create a document without giving any user define document id. i means like below

Here we are giving odwalla as key. so in document created with this name and its act as document ID. its really problem to tell name of document every time. Let me know the alternative solution to generate document ID automatically as like in Couchbase Synch Gateway.

INSERT INTO default (KEY, VALUE) VALUES (“odwalla”, { “productId”: “odwalla-juice123”, “unitPrice”: 4.40, “type”: “produc2t2”, “color”:“red”})


#4

Hi,

You can use any expression as your key, not just a string literal. So you can generate your key using any N1QL expression.


#5

Hey is it any possible take Coucahbase server auto incremented or some unique id by itself. instead of giving by me.

N1QL expression? can you please assist me to generate unique id from N1QL expression


#6

You can use the UUID() function to generate a unique value.