I have a barbershop app were every user can filter out the barbershops based on some criteria. I wanted to know if there is a way to only add filters when the user has set their preferred filters in the app. This is my how I attempted to do it which threw multiple errors:
bool avg_price = true;
bool barbers = true;
bool chairs = false;
bool dailyCustomers = false;
final db = await mongo.Db.create('serverCall');
db.open().then((value) {
barbershops = db.collection('Houses').find((avg_price)?mongo.where.lte("Price",15)
:mongo.where.lte("Price", 0).(barbers)?gte("barbers", 3):gte("barbers", 0).(chairs)?gt("chairs",
8):gt("chairs", 8).(dailyCustomers)?gt("minDailyCustomers", 15):gt("minDailyCustomers",15)
).forEach((element) {
print(element);
});
I know the code is a bit confusing, but it basically checks if the user has entered the preference, if yes then the bool relating to that preference will be set to true and the filter would need to be applied in that case.
My first week learning MongDB, so any help would be greatly appreciated.
Thanks Community!
question from:
https://stackoverflow.com/questions/65936883/can-mongo-db-perform-queries-only-if-a-condition-is-matched 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…