SoftInstigate / restheart

Rapid API Development with MongoDB
https://restheart.org
GNU Affero General Public License v3.0
807 stars 171 forks source link

confused with indexes - request clarification for the Collection Indexes documentation page #311

Closed tlawork closed 6 years ago

tlawork commented 6 years ago

I see how to create an index. I'm going through the tutorial and have /db/coll setup - then I setup an index called "myindex" with key="name" (my db/coll/_indexes is pasted below)

What I cant figure out is now that I have an index - how do I use it?

In my case - I have data
image

Here is what my index looks like from db/coll/_indexes

      {
        "_type": "INDEX",
        "v": 2,
        "unique": true,
        "key": {
          "name": 1
        },
        "ns": "db.coll",
        "sparse": true,
        "_id": "myindex"
      }

Expected Behavior

I am hoping to be able to GET /db/coll/MongoDB and get its record.

Current Behavior

/db/coll/MongoDB does not work /db/coll/myindex does not work /db/coll/_indexes/myindex...... and so forth - I cant figure out how to use the index I've created.

Context

Ultimately I am going to have a very complex collection with many fields - and it will be tied to a git repo (gerrit) All gerrit transactions are indexed by a change_number - and in my rest api I dont want to have to index the collection by _id - I need to index it by the change_num.

So I'm trying to do the same with the tutorial data and I would assume that /db/col/MongoDB (since name=MongoDB

Environment

Using restheart via docker-compose as in the tutorial on ubuntu 14 VM. I have not modified any of the yml files

mkjsix commented 6 years ago

Hi @tlawork

It seems to me your question is how to query documents with filters and not much related to indexes.

RESTHeart allows to work with plain MongoDB indexes. If instead you want to learn more about indexes, you need to read the MongoDB official documentation.

  1. MongoDb docs on indexes
  2. RESTHeart docs on indexes
tlawork commented 6 years ago

i have read those links though I appreciate the feedback. I was hoping to avoid having to have an ugly filter like this: http://abc.com/db/coll?filter="{'commit'='123456'} in lieu of http://abc.com/db/coll/123456

I thought thats how indexing worked - is that not the case with restHeart?

mkjsix commented 6 years ago

No it isn't, here we are talking about database indexes.

A database index is a data structure that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space to maintain the index data structure. Indexes are used to quickly locate data without having to search every row in a database table every time a database table is accessed. Indexes can be created using one or more columns of a database table, providing the basis for both rapid random lookups and efficient access of ordered records.

What you are instead trying to achieve is a parametric URL rewriting which dynamically maps query parameters to resources. I'd ask @ujibang if this would be achievable out of the box or you need to implement it programmatically from the RequestContext.

ujibang commented 6 years ago

Worth to read http://restheart.org/learn/query-documents/

The query executed requesting the collection resource uses the defined indexes speeding up the execution.

tlawork commented 6 years ago

thank you for the clarification I am closing the case.