I'm trying to perform a $gte query on a PouchDB index I've created. The query doesn't error but returns an empty array when there should be documents that match the clause. The idea is to get all docs that have timestamps from the last 30 days. The property that stores that value is not at the top level, it is part of a meta
property. eg.
{
_id: "76e7f205-b8c3-4cc6-abfb-77c98ca3a0d4",
_rev: "1-47f49534aa364f5c654b9574fa085005",
...
meta: {
created: 1501841768486
createdBy: "user@example.com"
}
}
I create my index successfully using the following:
recordingsDB.createIndex({
name: 'recent',
ddoc: 'recent',
index: {
fields: ['meta.created']
}
});
I then query it using:
let thirtyDaysAgo = moment(Date.now()).subtract(30, 'days').format('x');
//selector: { 'meta.created': { $gte: thirtyDaysAgo } },
return recordingsDB.find({
selector: { meta: { created: { $gte: thirtyDaysAgo } } },
sort: [{'meta.created': 'desc'}],
use_index: 'recent'
}).catch(function (err) {
console.log(err);
});
I have tried both syntax styles for querying sub-properties and neither work. The query doesn't actually fail or cause any errors - it just returns an empty array when I know there are documents that should match that query.
答案 0 :(得分:2)
您需要将ctrl.$onInit = $onInit;
function getFood(){
return $http.get('getFoodurl')
}
function getDrinks(){
return $http.get('getDrinksurl')
}
function combineFoodAndDrinks(data){
console.log("getFood data", data[0])
console.log("getDrinks data", data[1])
}
function $onInit() {
$q.all([getFood(), getDrinks()]).then(combineFoodAndDrinks);
}
包裹在thirtyDaysAgo
中,因为它是一个字符串,而您创建的日期是一个数字。类型差异对于pouchdb-find很重要,因为它使用与couchdb相同的基础索引标准,并且它们具有基于类型的collation order。