Skip to content

Getting Started with PouchDB #5399

@ceremcem

Description

@ceremcem

Well, it's not going well... The only example code is not working. Independently of that example, I could manage to put some test documents and get all of them from database, that's all:

update-view = (...x) ->
    console.log "Change detected! : ", x
    db.allDocs {include_docs: true, descending: true}, (err, doc) ->
        console.log "Docs: ", doc

db = new PouchDB \mydb
remote = 'https://MYUSER:MYPASS@MYUSER.cloudant.com/MYDB'
opts =
    continuous: yes
    on-change: update-view

db.replicate.to remote, opts
db.replicate.from remote, opts

user-id = 5
get-new-id = ->
    timestamp = new Date!get-time! .to-string 16
    "#{user-id}-#{timestamp}"

products =
    _id: get-new-id!
    title: \products
    product-list:
        * name: \cake
          unit: \piece
          best-served: \cold
        * name: \water
          unit: \kg
          best-served: \hot


db.put products, (err, result) ->
    if not err
        console.log "success!"
    console.log "result: ", result

Second step is getting a view value:

$ curl https://MYUSER:MYPASS@MYUSER.cloudant.com/MYDB/_design/getTitles/_view/new-view
{"total_rows":7,"offset":0,"rows":[
{"id":"5-1557feee287","key":"5-1557feee287","value":"domates"},
{"id":"5-1557ff6c0b3","key":"5-1557ff6c0b3","value":"domates"},
{"id":"5-1557ff854f8","key":"5-1557ff854f8","value":"domates"},
{"id":"5-1557fffff92","key":"5-1557fffff92","value":"domates"},
{"id":"5-1558000c0d5","key":"5-1558000c0d5","value":"domates"},
{"id":"5-1558000f067","key":"5-1558000f067","value":"domates"},
{"id":"5-15582153a32","key":"5-15582153a32","value":"domates"}
]}

I can't figure out how to get this result via PouchDB.

Isn't there any example for such a startup?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions