这是我的db.find():
db.createIndex({索引:{字段:['username','date'],名称:'usernameDateIndex', ddoc: usernameDateIndex } })。then(()= > { db.find({选择器:{用户名:'org.couchdb.user:'+名称},排序:[{用户名:'desc'},{date:'desc'}], use_index:'usernameDateIndex'})。then(result => { //工作正常,我明白了预期})。catch(错误=> {}); })。catch(错误=> {});这可以正常工作并返回包含六个文档的数组。然后,我删除一个这样的文档:
doc._deleted = true; db.put( doc ).then(response => { // db.allDocs()返回5个文档,这是正确的 // db .find()返回一个空数组})。catch(error => {});删除后,db.AllDocs()正常工作,但db.createIndex和db.find相同()以上列出的返回和空数组。我还尝试了删除后没有db.createIndex()的db.find(),但是我仍然得到一个空数组,并且没有错误。
我丢失了在这里迈出一步?删除后是否需要进行某种提交?我是否需要删除索引并重新创建?我是否需要使用CouchDB远程服务器强制复制?不确定发生了什么。
最后一件事,这是一个React Native应用程序,它使用pouchdb-react-native和pouchdb-find包。它的后备存储是AsyncStorage。
解决方案在此答案,根据答案的第2项:
也许是您遇到问题的原因。
Here is my db.find():
db.createIndex({ index: { fields: ['username', 'date'], name: 'usernameDateIndex', ddoc: "usernameDateIndex" } }).then(() => { db.find({ selector: { username: 'org.couchdb.user:' + name }, sort: [{username: 'desc'}, {date:'desc'}], use_index: 'usernameDateIndex' }).then(result => { // Works fine. I get what is expected }).catch(error => { }); }).catch(error => { });This works fine and returns an array with six docs. I then delete one doc like this:
doc._deleted = true; db.put( doc ).then(response => { // db.allDocs() returns 5 docs this is correct // db.find() returns an empty array }).catch(error => { });After the delete, db.AllDocs() works correctly but the same db.createIndex and db.find() listed above returns and empty array. I have also tried db.find() after the delete without the db.createIndex() and I still get an empty array and I get no errors.
Am I missing a step here? Do I need to do some sort of commit after the delete? Do I need to delete the index and create it again? Do I need to force replication with my CouchDB remote server? Not sure what is going on.
One last thing, this is a React Native app that is using pouchdb-react-native and pouchdb-find packages. It's backing storage is AsyncStorage.
解决方案Take a loot at this answer, according to item 2 of the answer:
Maybe that's the cause of your issue.
更多推荐
从数据库删除6个对象中的1个后,PouchDB find()返回空数组
发布评论