我一直在尝试使用 flutter dart 从我的 realmdb 中获取 type 的 sum。不幸的是,我不断收到运行时错误:
RealmException(RealmException:错误代码:36。消息:操作'.@sum'不能应用于属性'type',因为它不是列表)
这是我的数据库模式:
导入'package:realm/realm.dart';
part 'realmdb.g.dart';
@RealmModel()
class _Item {
@MapTo('_id')
@PrimaryKey()
late ObjectId id;
late String type;
late String description;
late double value;
@MapTo('owner_id')
late String ownerId;
DateTime? date;
}
查询:
var groceries = realm.query('[email protected] =="Groceries"');
这是我收藏的文件:
{"_id":{"$oid":"6416459ebae4d0e8702d0e27"},"date":{"$date":{"$numberLong":"1679181214346"}},"description":"Bit Coin","owner_id":"6414e8ad4791938608072411","type":"Crypto","value":{"$numberDouble":"5987.0"}}
我也想从任何类型中获取总和。像“杂货”总和 = 365,或“休闲”总和 = 643 等
即使从https://www.mongodb.com/docs/realm/realm-query-language/通过转换他们的例子阅读官方网站
"[email protected] > 100" into '[email protected] =="Groceries"' i
t 还是不行。
有谁知道如何解决这个问题?
非常感谢您的帮助。
非常感谢。
OlaSebi88
var groceries = realm.query('[email protected] =="Groceries"');