You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "Tony Sun (JIRA)" <ji...@apache.org> on 2016/02/04 19:33:40 UTC

[jira] [Commented] (COUCHDB-2927) Move $elemMatch into view query instead of in-memory

    [ https://issues.apache.org/jira/browse/COUCHDB-2927?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15132733#comment-15132733 ] 

Tony Sun commented on COUCHDB-2927:
-----------------------------------

[~nolanlawson]: So right now, the way a user can index an array's individual elements is by doing something like:
```javascript
{
"fields": { "tags.0", "tags.1", "tags.2"}
}
```
Now the user can query individual elements via
```javascript
"tags.0" : "sunny"
```
So now what you're asking is that at indexing time, the user just does 
```javascript
{
"fields": { "tags"}
}
```
We recognize that the "tags" field is an array and we store only one field "tags" with values "sunny", "green" and "relaxing".
An $elemMatch would then do
```javascript
{"tags" : {"$elemMatch" : {"$eq" : "sunny"}}
```
This would then just do a range scan of tags underneath the covers and return the document back.

The concern with this involves nested arrays and objects. Let's say you have a document that looks like:
```javascript
{
  _id: 'tahiti',
  tags: [{"name" : {"first" : "tony", "last" : sun }]
}
```
This would still work:
```javascript
{"tags" : {"$elemMatch" : {"name" : {"first" : "tony", "last" : "sun" }}
```
But what if you only wanted the last name?
{"tags" : {"$elemMatch" : {"name.last" : "sun" }}

Then the range value for the key "tags" would be incorrect for the search.



> Move $elemMatch into view query instead of in-memory
> ----------------------------------------------------
>
>                 Key: COUCHDB-2927
>                 URL: https://issues.apache.org/jira/browse/COUCHDB-2927
>             Project: CouchDB
>          Issue Type: Improvement
>          Components: Mango
>            Reporter: Garren Smith
>
> $elemMatch is in-memory - I think we should just auto-index arrays, because otherwise people have absolutely no way of doing a simple thing like categories/tags in pouchdb-find and are forced to use map/reduce instead



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)