pouchdb / geopouch

Spatial plugin from PouchDB extracted and supporting N dimentional coordinates.
http://pouchdb.com
Apache License 2.0
85 stars 14 forks source link

Design docs Only works once #15

Closed wasa4587 closed 8 years ago

wasa4587 commented 8 years ago

I create the test design doc

  localDB.put({
    _id: '_design/foo',
    spatial: {
      bar: function (doc) {
        if(doc.type=='item')
        emit(doc.geometry);
      }.toString()
    }
  })

Then insert a dummy Point

localDB.post({geometry: {
                    type: "Point",
                    coordinates: [20.8215207,
      -102.76524380000001]
                  },type:'item'})

First Query, works!

                    localDB.spatial(
                        'foo/bar', 
                        [
                            20.814393839832164, -102.79158198011476, 20.82041090010421, -102.73295961988526
                        ]).then(function (resp) {
                            console.log(resp)
                        }).catch(function(err) {
                            console.log(err)
                        });

when i run the last query again, it returns an empty array []

Windows 8.1, Google Chrome 52.0.2743.116 m

On Firefox 47.0.1, it returns

Object { status: 404, name: "not_found", message: "missing", error: true, reason: "missing", stack: "" }

Using a tmp view works well

calvinmetcalf commented 8 years ago

ok let me look into it

calvinmetcalf commented 8 years ago

(edited your comment, fyi the back ticks can be used for multi line code samples)

calvinmetcalf commented 8 years ago

um so I'm shocked your query actually works as your point is located outside of the bounding box, but once I adjust things then the following code works

var Pouch = require('pouchdb');

var Spatial = require('./');
Pouch.plugin(Spatial);
var localDB = new Pouch('./local/test');
localDB.put({ _id: '_design/foo', spatial: { bar: function (doc) { if(doc.type=='item') emit(doc.geometry); }.toString() } }).then(function () {
  console.log('put design');
  return localDB.post({geometry: { type: "Point", coordinates: [20.8215207, -102.76524380000001] },type:'item'})
}).then(function () {
  console.log('put point');
  return localDB.spatial( 'foo/bar', [ 20, -103, 21, -102 ]);
}).then(function (resp) {
  console.log('query 1');
  console.log(resp);
  return localDB.spatial( 'foo/bar', [ 20, -103, 21, -102 ])
}).then(function (resp) {
  console.log('query 2');
  console.log(resp);
}).catch(function(err) {
  console.log('err')
  console.log(err)
});

can you provide some details of what your setup is that leads to this?

wasa4587 commented 8 years ago

Thanks for answering.

I'm using this on ionic framework project. It's interesting, your code works well. Seems it works when you just post an item, and it only shows the item you posted.

i built the geopouch for using on browser

<!-- index.html -->
  <script src="lib/pouchdb/dist/pouchdb.min.js"></script>  
  <script src="lib/geopouch/geopouch.js"></script>  

then every request, it return only 1 item, and i think it shuold returns an incremental numer of items (first request 1 item, 2nd request 2 items, so on)

// app.js
var localDB = new PouchDB("test");
PouchDB.plugin(geopouch);

//localDB.put({ _id: '_design/foo', spatial: { bar: function (doc) { if(doc.type=='item') emit(doc.geometry); }.toString() } })

localDB.post({geometry: { type: "Point", coordinates: [20.8215207, -102.76524380000001] },type:'item'}).then(function () {
  console.log('put point');
  return localDB.spatial( 'foo/bar', [ 20, -103, 21, -102 ]);
}).then(function (resp) {
  console.log('query 1');
  console.log(resp);
  return localDB.spatial( 'foo/bar', [ 20, -103, 21, -102 ])
}).then(function (resp) {
  console.log('query 2');
  console.log(resp);
}).catch(function(err) {
  console.log('err')
  console.log(err)
});
calvinmetcalf commented 8 years ago

hm looks like it's picking up the previous index, looking into it

calvinmetcalf commented 8 years ago

yeah there was a problem in how it reopened databases in a dep, fixed the dep and published a new version of the dep, about to publish a new version of geopouch that relies on that version including the build version of the library

calvinmetcalf commented 8 years ago

done

wasa4587 commented 8 years ago

thank you @calvinmetcalf