n1ql

Couchbase update for multiple set

ぃ、小莉子 提交于 2019-12-23 17:19:38
问题 I have the following n1ql query: UPDATE default USE KEYS '557a7628-1217-4974-95cf-d64247c560cd' SET p.last_seen_message_id = 'e5010536-7fde-42c1-9fea-e4a29e560f53', p.last_seen_message_text = 'hello' FOR p IN participants WHEN p.id = '119c35ab-a1cc-4e9f-bab5-d58d6d396623' END WHERE doc_type = 'conversation' RETURNING default.* With this query, I would like to set two properties in an array's element, but only the last one ( p.last_seen_message_text = 'hello' ) has any effect. The first (in

Filter documents using n1ql

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-23 02:38:12
问题 I have two types of documents with a relation one to many and I need to get only one document basing on the latest date value. Here it is an example: Document Type (Singer): { "id":"223-34fd-35325-dsf-343f", "resourceType":"Singer", "name":"Paul" } Document Type (Album1): { "id":"456-d435-43g346-43-436tf-345g", "name":"Amazing night", "author":"223-34fd-35325-dsf-343f", "creationDate": "2017-05-12T07:57:51.458Z" } Document Type (Album2): { "id":"878-ffe6-43gs56-5hn7-ffgdd-345hd", "name":"Be

Couchbase N1QL join query

荒凉一梦 提交于 2019-12-19 04:23:30
问题 need help with a query in Couchbase enviroment. Both document 1 and document 2 is in the same bucket. First the query will get the document message1 using this query: SELECT uid, message, sent_by FROM bucket USE KEYS "message1" Second, it need to get username from document 2. How can i create a join statement that will fetch username from a given document name, using the query above? Overview Document 1 document name = message1 [ { "uid": "1", "message": "hello", "sent_by": "username" } ]

Query sync gateway buckets using N1QL

左心房为你撑大大i 提交于 2019-12-13 13:15:22
问题 I wanted to know if it's possible to query the sync gateway buckets using N1QL? Does it behave as a normal couchbase bucket or because of the metadata that sync gateway adds, is it possible to query it only through Rest APIs? Currently I have a webhooks handler, which keeps a replica of the documents residing under sync gateway buckets. I need to do some aggrgations which need to be pushed back to clients. So, can I do all this heavy lifting directly trhough n1ql on sync gateway or using

How to get latest document from specific date?

坚强是说给别人听的谎言 提交于 2019-12-13 03:39:45
问题 I'm trying to get the latest document from specified date (variable) in Couchbase and N1QL on a very large database (150 millions documents each month). The latest document from a date could be any time (previous second or last month). Note, the date is in Unix Epoch. Here is a structure of the documents: { "type" : "person", "id":"001", "name":"John Doe", "date":"1491199810.435" } I have index on date: CREATE INDEX `date` ON `mytable`(`date`) WITH { "defer_build"=true } Usually in Postgres

Update specific object in the array of object in couchbase 4.1

北城余情 提交于 2019-12-12 02:21:52
问题 I have following doc with doc key cart::16 { "_type": "NSCart", "_metadata": { "created_at": 1473075845614, "updated_at": null }, "_id": "f28bc609-6aba-47e5-8e83-5bee2397566f", "userId": "B1HvmsLj57c9235c", "items" : [{ "itemId": "N1d55j8m4xr", "seller": "ByD9T4Ks57cbbd8e", "license": null, "basePrice": 0 },{ "itemId": "L9nd6Dswl4v", "seller": "ByD9T4Ks57cbbd8e", "license": E122, "basePrice": 500, "eCharge": 10, "total": 510 }] } now i want to update a doc where item id is N1d55j8m4xr like

Couchbase N1QL query data between two days without time

大憨熊 提交于 2019-12-11 17:56:50
问题 I want to retrieve data from a Couchbase bucket with N1QL between two days (from 00:00:00.000 start date time until 23:59:59.999 end date time) Is it enough to provide the dates without time, like this: SELECT c.* FROM customer c WHERE c.start BETWEEN '2017-10-09' AND '2017-10-10' Or do I need to provide the time explicitly: SELECT c.* FROM customer c WHERE c.start BETWEEN '2017-10-09T00:00:00.000Z' AND '2017-10-10T23:59:59.999Z') ? 回答1: Couchbase date in ISO-8601 are string comparable. The

Unable to create primary index on couchbase using groovy script

守給你的承諾、 提交于 2019-12-11 15:33:30
问题 I am not able to Create primary index on couchbase using groovy script. Below are the lines of code I used:- @Grab('com.couchbase.client:java-client:2.2.6') import java.util.concurrent.CountDownLatch; import com.couchbase.client.java.Bucket; import com.couchbase.client.java.Cluster; import com.couchbase.client.java.CouchbaseCluster; import com.couchbase.client.java.document.JsonDocument; import com.couchbase.client.java.document.json.JsonObject; import com.couchbase.client.java

N1QL Concatenate many children rows into single string

可紊 提交于 2019-12-11 11:45:48
问题 Consider in Couchbase I have a person database, with 3 documents: Person A Child AA Grand AAA Grand AAB Child AB Grand ABA Grand ABB Person B Person C Child CA Child CB Grand CBA Is there an easy way to turn this into following results using N1QL? I am trying to display each person with their grand children displayed into strings? Person A, Grand: "AAA, AAB, ABA, ABB" Person B, Grand: "" Person C, Grand: "CBA" 回答1: You can do the following: SELECT p.name AS p, ENCODE_JSON(ARRAY_AGG(g.name))

How to connect to Couchbase server 4.0(Beta) N1QL in windows?

雨燕双飞 提交于 2019-12-11 08:49:13
问题 I have just installed Couchbase Server 4.0(beta) and try to run N1QL Query, but could not connect it. When I try to run cbq-engine.exe -couchbase http://localhost:8091/ The command prompt closed automatically. When try to use cb.exe -engine=http://localhost:8091/ It also does not work. Is it bug? How to connect it? (I am running cbq.exe from bin directory of installation) 回答1: As documented in the Running your first N1QL query section of the Couchbase Server manual the port the cbq needs to