NutzCN Logo
问答 1.r.61版本 mongodb 如何写$or
发布于 2300天前 作者 qq_ca9d2523 1784 次浏览 复制 上一个帖子 下一个帖子
标签:

nutz及monggo版本1.r.61

代码如下

ZMoDoc cnd = ZMoDoc.NEW("$or",
                                Lang.list(ZMoDoc.NEW().all("adcode", contry),
                                          ZMoDoc.NEW().all("adcode",
                                                           province)));
        
        ZMoDoc keys = ZMoDoc.NEW();
        keys.put("gid", 1);
        keys.put("_id", 0);

        DBCursor cursor = goodsLocDao().find(cnd, keys);

日志如下:

org.nutz.mongo.ZMoCo.find(ZMoCo.java:215) - db.goodsLoc.find({ "$or" : [ [ { "adcode" : { "$all" : [ "000000"]}} , { "adcode" : { "$all" : [ "210000"]}}] , [ { "adcode" : { "$all" : [ "000000"]}} , { "adcode" : { "$all" : [ "210000"]}}]]}, { "gid" : 1 , "_id" : 0})
[DEBUG] 2018-09-05 11:25:33.496 com.mongodb.diagnostics.logging.SLF4JLogger.debug(SLF4JLogger.java:56) - Sending command {find : BsonString{value='goodsLoc'}} to database xiaoi on connection [connectionId{localValue:2, serverValue:1690}] to server 192.168.0.168:27017
[WARN ] 2018-09-05 11:25:33.503 org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:28) - Error@/goods/test :
com.mongodb.MongoQueryException: Query failed with error code 2 and error message '$or/$and/$nor entries need to be full objects' on server 192.168.0.168:27017
	at com.mongodb.operation.FindOperation$1.call(FindOperation.java:521)
	at com.mongodb.operation.FindOperation$1.call(FindOperation.java:510)
	at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:431)
	at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:404)
	at com.mongodb.operation.FindOperation.execute(FindOperation.java:510)
1 回复

换新版, 前几天fix了一个相关的bug

添加回复
请先登陆
回到顶部