I'm not sure how to figure out how to sort my documents using a Mango query. Any help would be greatly appreciated:
I do the following find query and get the following error:
return db.find({ sort: ['timestamp'], selector: {$and: [{type:"revision"},{doc_id: doc_id}] } })
Note, if I do the following I also get the same error:
return db.find({ sort: ['timestamp'], selector: {$and: [{type:"revision"}] } })
{ error: 'no_usable_index', reason: 'No index exists for this sort, try indexing by the sort fields.', name: 'no_usable_index', status: 400, message: 'No index exists for this sort, try indexing by the sort fields.' }
I created a filter like so:
db.createIndex({
index: {fields: ['type', 'timestamp']}
})
This is what pops up in my design documents:
{
"_id": "_design/b661014513bf0c13270a9033d6d1c1853a8b5dbf",
"_rev": "1-1d871456b0a78952845705f4e8dd2c26",
"language": "query",
"views": {
"b661014513bf0c13270a9033d6d1c1853a8b5dbf": {
"map": {
"fields": {
"type": "asc",
"timestamp": "asc"
},
"partial_filter_selector": {}
},
"reduce": "_count",
"options": {
"def": {
"fields": [
"type",
"timestamp"
]
}
}
}
}
}
from No index exists while trying to sort using an indexed field (Mango Queries)
No comments:
Post a Comment