rethinkdb

When will rethinkdb return a cursor

自作多情 提交于 2019-12-06 12:05:36
问题 I notice that r.table('xxx') not always return a cursor but also sometimes just return docs directly Is the cursor client side implementation only or there are some special things server did to perform queries associate with a cursor ? If it has somethings related to server , what is it and when will I receive a cursor For example I specify result offset and size with skip and limit in the query. Will server return a cursor or just result docs ? 回答1: A driver returns a cursor when the query

rethinkdb with filter and getNearest commands

故事扮演 提交于 2019-12-06 06:54:33
问题 How can execute getNearest query about the result of other command, for example a filter command? var point = r.point(-122.422876,37.777128); r.db('test').table('users'). filter({tags : 'tag'}). getNearest(point, {index: 'geodata', maxResults: 30, unit :'km'}) I have a 'users' table: [ {id: 1, tags : ['music', 'cups'], geodata: r.point()} {id: 2, tags: ['music', 'play'], geodata: r.point()} ] First I want to filter by 'tags' field and then return the nearest. The query that I have specified

Rethinkdb removing data from documents

梦想的初衷 提交于 2019-12-06 06:52:36
I'm trying to remove some portions of data from documents with given fairly simple structure, which will get much deeper and heavier than this as the project goes: { id: "...", name: "...", phone: "...", data: { key1: "val1", ... } ... } I'm aware that there is no way of updating/removing sections from the nested parts other than replacing the whole tree with updated tree. For example, if I want to delete key1 from document data, I need to update the documents data section with a copy of it where key1 is not contained document.update({data: new dict without key1}) Is there any eaiser way of

How can I modify array fields in place?

微笑、不失礼 提交于 2019-12-06 01:43:23
问题 Let's say I have this object: { "id": "1a48c847-4fee-4968-8cfd-5f8369c01f64" , "sections": [ { "id": 0 , "title": "s1" } , { "id": 1 , "title": "s2" } , { "id": 2 , "title": "s3" } ] } How can I directly change 2nd title "s2" to other value? without loading the object and save again? Thanks. 回答1: Update plus the changeAt term: r.table('blog').get("1a48c847-4fee-4968-8cfd-5f8369c01f64").update(function(row){ return { sections: row('sections').changeAt(1, row('sections')(1).merge({title: "s2

How to query a multi index in RethinkDB over an array of objects

梦想的初衷 提交于 2019-12-05 22:15:28
问题 I'm working with a data set that looks something like this: "bitrates": [ { "format": "mp3" , "rate": "128K" } , { "format": "aac" , "rate": "192K" } ] , "details": [ ... ] , "id": 1 , "name": "For Those About To Rock We Salute You" , "price": 1026 , "requires_shipping": false , "sku": "ALBUM-1" } And I wanted to create a secondary index on bitrates , flexing {multi:true} . This was my attempt: r.db("music").table("catalog").indexCreate("bitrates", {multi: true}) The index built just fine,

How do I create a compound multi-index in rethinkdb?

寵の児 提交于 2019-12-05 09:06:55
I am using Rethinkdb 1.10.1 with the official python driver. I have a table of tagged things which are associated to one user: { "id": "PK", "user_id": "USER_PK", "tags": ["list", "of", "strings"], // Other fields... } I want to query by user_id and tag (say, to find all the things by user "tawmas" with tag "tag"). Starting with Rethinkdb 1.10 I can create a multi-index like this: r.table('things').index_create('tags', multi=True).run(conn) My query would then be: res = (r.table('things') .get_all('TAG', index='tags') .filter(r.row['user_id'] == 'USER_PK').run(conn)) However, this query still

Querying array of nested objects

女生的网名这么多〃 提交于 2019-12-05 03:55:56
Say I have this JSON (sample - a real-life example can be found at apple itunes rss feed ) stored in a RethinkDB table called 'test': { "feed": { "entry": [ { "title": { "label": "Some super duper app" }, "summary": { "label": "Bla bla bla..." } }, { "title": { "label": "Another awsome app" }, "summary": { "label": "Lorem ipsum blabla..." } } ] } } How would I write a ReQL query in JavaScript in order to fetch the summary of all entries ( entry ) which have title containing the string "xyz"? I expect the query result to return an array of matching entry objects, not an array of matching feed .

RethinkDB - Find documents with missing field

萝らか妹 提交于 2019-12-05 02:08:30
I'm trying to write the most optimal query to find all of the documents that do not have a specific field. Is there any better way to do this than the examples I have listed below? // Get the ids of all documents missing "location" r.db("mydb").table("mytable").filter({location: null},{default: true}).pluck("id") // Get a count of all documents missing "location" r.db("mydb").table("mytable").filter({location: null},{default: true}).count() Right now, these queries take about 300-400ms on a table with ~40k documents, which seems rather slow. Furthermore, in this specific case, the "location"

How can I migrate my MongoDB to RethinkDB?

瘦欲@ 提交于 2019-12-05 00:10:16
问题 How can I migrate my MongoDB collections to RethinkDB tables? I'm not concerned about changing my old Mongo _id 's to Rethink id 's because they will be ignored in my implementation, and I'm not concerned about them cluttering my data. 回答1: I wrote a quick BASH script to solve this. Because I only had the JavaScript RethinkDB driver, I had to install the python driver first so I could use rethinkdb import . For this example, I am migrating the mongo collections: users , pinboards , and

When will rethinkdb return a cursor

守給你的承諾、 提交于 2019-12-04 17:14:36
I notice that r.table('xxx') not always return a cursor but also sometimes just return docs directly Is the cursor client side implementation only or there are some special things server did to perform queries associate with a cursor ? If it has somethings related to server , what is it and when will I receive a cursor For example I specify result offset and size with skip and limit in the query. Will server return a cursor or just result docs ? A driver returns a cursor when the query returns a stream. Basically when the server produces a stream (a sequence that is lazily computed), the