How to use emberfire to query the firebase database for all elements named equalTo xyz in ember.js 2.0.0?

I am new to ember.js and firebase. I tried to do what I needed to query the DB for the key corresponding to a specific value.

According to guides.emberjs.com , the following example should work:

this.store.query('person', { filter: { name: 'Peter' } }).then(function(peters) { // Do something with `peters` }); 

But this is not so. Apparently, because I use hadron fire. After literal hours of browsing the Internet, there was no clear solution.

emberfire docs talk about the available arguments.

Arguments

orderBy - String - Property ...
.
.
,

equalTo - String, Number, Null - creates a query that includes children that match the specified value.

And imagine an example ...

 // app/routes/dinosaurs.js export default Ember.Route.extend({ model: function() { return this.store.find('dinosaur', { orderBy: 'height', limitToLast: 10, startAt: 5 }); } }); 

Although not shown how to use "equalTo". I tested them all, but I did not understand how equalTo works.

There are other solutions in SO, but they are all pre-v2.0.0. Therefore, I do not think that they will work post v2.0.0.

Ember.js Debug Information:

 DEBUG: ------------------------------- DEBUG: Ember : 2.0.0 DEBUG: Ember Data : 2.0.0 DEBUG: Firebase : 2.3.1 DEBUG: EmberFire : 1.6.0 DEBUG: jQuery : 1.11.3 DEBUG: ------------------------------- 

Database Used: https://shoutoutdb.firebaseio.com/users

I don’t quite understand how equalTo should work here, but I don’t understand either. Hope someone here wants to help.

If you think that the question needs some improvement, we ask you to ask. I described this in detail, as I thought I should. Thank you in advance.:)

EDIT: The code I tried to use:

 $E.store.find('user',{name:'Alpha'}).then( function (data) { //stuff done with the data } ); 

I also tried several different versions of this code. Nothing worked, so I don't think it's worth mentioning them here.

+6
source share
2 answers

Using the capabilities of the queries, you can combine orderByChild and equalTo to get the desired result:

 ref.child('people').orderByChild('name').equalTo('Peter').on('value', ...); 

In the web API example, there is an example for equalTo and in the web guide for complex queries .

So, in EmberFire, this will mean the following:

 this.store.query('person', { orderBy: 'name', equalTo: 'Peter' }); 
+15
source

Although the answer to tstirrat will force you in most cases, there is an Ember admin to request a search in firebase.

You can check it out here:

https://www.npmjs.com/package/ember-emberfire-find-query

+1
source

All Articles