mongodb日期范围_Mongodb Java查询日期范围

I needed to find all the records in mongo db within two date ranges using Mongo Driver[3.4.0] for Java.

Example:

I have books Collection.

{

"_id" : ObjectId("5acb40d27d63b61cb002bafe"),

"title" : "WingsOfFire",

"pub-date" : ISODate("2013-10-02T00:00:00.000Z"),

"rel-date" : ISODate("2013-11-02T00:00:00.000Z")

}

Like above I have 100s of documents.

I need to find all records wherein pub-date > rel-date.

I am using Mongo DB version 3.2.6

I tried to use $expr operator but it seems to work with only Mongo 3.6+

Not able find cleaner solutions for above requirement.

Please clarify.

解决方案

You might want to try $where-Operator:

db.books.find({ "$where": "this.pub-date > this.rel-date"});

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值