For a general answer, please refer to this explanation Doug Stevenson gave.
In short, an inequality operation is not supported because of the way Firestore's indexes work.
In your specific problem, there is a simple way to solve it:
You can easily remove the single document you do not need client side, which will barely makes a difference in data and processing power usage.
Because I suppose that you will still want to use StreamBuilder
, I will show a way to remove the document with your user's email from the List<DocumentSnapshot>
you get from snapshot.data.docments
:
StreamBuilder(
stream: Firestore.instance
.collection(USERS_COLLECTION)
.snapshots(),
builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
if (!snapshot.hasData)
return Container(child: Text(""));
final List<DocumentSnapshot> documents = snapshot.data.documents.where((snapshot) => snapshot.data["email"] != _useremail);
var documentsLength = documents.length;
// ...
});
The adjustments lie in the removal of the where
in your query and the addition of the following line of code:
final List<DocumentSnapshot> documents =
snapshot.data.documents.where((snapshot) => snapshot.data["email"] != _useremail);
This removes all documents that are equal to _useremail
, which is equivalent to your request.
Be aware that you will need to work with documents
after that, in exactly the way I did with documentsLength
.
This will also work if you want to remove multiple documents, but will obviously get more expensive the more "unnecessary" documents you retrieve. Thus, if you believe that you are doing too many document reads that are not necessarily required, you should think about adjusting your database structure.
Also, as mentioned here, you do not need to use the new
keyword in Dart 2.