how to add two orderBy in firebase code example
Example 1: orderBy firebase angular
import { map, take } from 'rxjs/operators';
import { Observable } from 'rxjs';
public allProducts: Observable<any[]>;
public amazonCollection: AngularFirestoreCollection;
this.amazonCollection = this.afs.collection('amazon', (ref) =>
ref.orderBy('voteCount')
);
this.allProducts = this.amazonCollection.snapshotChanges().pipe(
map((actions) => {
return actions.map((a) => {
return { id: a.payload.doc.id, ...a.payload.doc.data() };
});
})
);
Example 2: multiple query at once in firebase
function doSomething(...){
let result1 = [];
let result2 = [];
admin.firestore().collection('...').where('some condition').get()
.then((results: any)=>{
results.forEach((element: any)=>{
if(some other condition){
result1.push(element);
}
})
.catch((error: any)=>{
admin.firestore().collection('...').where('yet another condition').orderBy(...).get()
.then((results: any)=>{
results.forEach((element: any)=>{
result2.push(func(element))
})
.catch((error: any)=>{
return makeCalculation(result1, result2);
}