MongoDB SubString生成的语句不正确... 返回
执行下面查询时报错
var cardBin = _b2eBankRepository .AsQueryable() .Where(w => w.CardLength == transfer.PayeeAcNo.Length && w.Status == 1 && w.CardBin == transfer.PayeeAcNo.Substring(0, w.CardBinLength) ).First();
异常信息为
MongoDB.Driver.MongoCommandException:“Command aggregate failed: PlanExecutor error during aggregation :: caused by :: $substrBytes: length must be a numeric type (is BSON type string).”
生成语句如下:
aggregate b2e_bank [{ "$match": { "$and" : [{ "card_length" : 16 }, { "status" : 1 }, { "$expr" : { "$eq" : ["$card_bin", { "$substrBytes" : ["$9999999999999999", 0, "card_bin_length"] }] } }] } }, { "$skip": 0 }, { "$limit": 1 }]
card_bin_length少了$
热忱回答(13)
-
fate sta VIP0
2025/8/20好的我处理一下。
0 回复 -
fate sta VIP0
2025/8/20SqlSugar.MongoDbCore 5.1.4.250
已修复,过五分钟安装
0 回复 -
o(´^`)o VIP0
2025/8/20我上面还漏了一处错误
现在语句为
aggregate b2e_bank [{ "$match": { "$and" : [{ "card_length" : 16 }, { "status" : 1 }, { "$expr" : { "$eq" : ["$card_bin", { "$substrBytes" : ["$9999999999999999", 0, "$card_bin_length"] }] } }] } }, { "$skip": 0 }, { "$limit": 1 }]红色部分应该没有$
辛苦大佬再修复一下
0 回复 -
fate sta VIP0
2025/8/20@o(´^`)o:提供有错的代码。
0 回复 -
fate sta VIP0
2025/8/209999999999999999 是怎么传给ORM的。
0 回复 -
fate sta VIP0
2025/8/20
我这边测试了没有问题
0 回复 -
fate sta VIP0
2025/8/20
这个是源码里面的DEMO. 在GITHUB可以下载DEMO
0 回复 -
o(´^`)o VIP0
2025/8/20我的场景和Demo的不一样
var name = "acbd"; //name 是外部传入,不是列名 var query = db.Queryable<Student>() .Where(it=> "ac" == name.Substring(0,it.SchoolId)) .Select();

源码的memberName应该也要做判断吧...0 回复 -
fate sta VIP0
2025/8/20那你要写一个我可以重现的例子
0 回复 -
fate sta VIP0
2025/8/20我不清楚你是如何重现的
0 回复 -
o(´^`)o VIP0
2025/8/20var payeeAcNo= "1234567890123456"; var cardBin = _b2eBankRepository .AsQueryable() .Where(w => w.CardLength == payeeAcNo.Length && w.Status == 1 && w.CardBin == payeeAcNo.Substring(0, w.CardBinLength) ).First();
这个查询生成的语句就是
aggregate b2e_bank [{ "$match": { "$and" : [{ "card_length" : 16 }, { "status" : 1 }, { "$expr" : { "$eq" : ["$card_bin", { "$substrBytes" : ["$1234567890123456", 0, "$card_bin_length"] }] } }] } }, { "$skip": 0 }, { "$limit": 1 }]
正确的应该为
aggregate b2e_bank [{ "$match": { "$and" : [{ "card_length" : 16 }, { "status" : 1 }, { "$expr" : { "$eq" : ["$card_bin", { "$substrBytes" : ["1234567890123456", 0, "$card_bin_length"] }] } }] } }, { "$skip": 0 }, { "$limit": 1 }]0 回复 -
fate sta VIP0
2025/8/20好的。。我处理一下
0 回复 -
fate sta VIP0
2025/8/20SqlSugar.MongoDbCore 5.1.4.252
0 回复