Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A simple where clause in flutter/firebase database

Today I started experimenting with Firebase Live database. Maybe I'm thinking too much in sql terms. But what I want to do is get a record from my database where a value equals a variable with flutter. My table looks like this:

enter image description here

What I'm trying to achieve is something like this:

FirebaseDatabase.instance.reference().child('users').where('User_id', 1508)

Like I said. I'm a complete beginner when it comes to Live Databases. I hope someone can help me with this issue I'm having.

Kind regards, Namanix

like image 715
Kevin Walter Avatar asked Apr 11 '18 14:04

Kevin Walter


People also ask

How do you query data from firestore in Flutter?

You will need to add the list of query options that a user will search for. At the time when you are pushing data into the firestore you can do is to create the search query options. This will result in pushing all the queries that a user can search for.


2 Answers

According to firstore docs

Firestore.instance
  .collection('talks')
  .where("topic", isEqualTo: "flutter")
  .snapshots()
  .listen((data) =>
    data.documents.forEach((doc) => print(doc["title"])));
like image 182
Nomi Avatar answered Oct 19 '22 00:10

Nomi


If you have the user id in a variable for example called:

String uid = currentUser.uid;

then you can do the following:

FirebaseDatabase.instance.reference().child('users/$uid')

Update I think this is what you are asking about

FirebaseDatabase.instance
                    .reference().child("users")
                    .orderByChild("User_id")
                    .equalTo($this.userId)
like image 23
Shady Aziza Avatar answered Oct 19 '22 00:10

Shady Aziza