Home > Java > javaTutorial > body text

Implementation case of mongoDB multi-condition query in Java

黄舟
Release: 2017-09-25 10:39:57
Original
2706 people have browsed it

This article mainly introduces the multi-condition query of mongoDB implemented in Java. It has certain reference value. Friends who need it can refer to it.

Requirements: In the mongDB client, we can easily implement multi-condition query, so how to implement it when using java operation?

Client code:


db.url.find({index:4,status:0,url:{$regex:"2016"}}).limit(1)
Copy after login

java code mainly uses DBObject


BasicDBObject doc5 = new BasicDBObject();
 doc5.put("index", 3);
 doc5.put("status", 0);
 //doc5.put("url", "{$regex:'2016'}");错误的写法
 BasicDBObject doc3 = new BasicDBObject();
 doc3.put("$regex", "2016");
 doc5.put("url", doc3);
 FindIterable<document> find = col.find(doc5);</document>
Copy after login

Summary

The above is the detailed content of Implementation case of mongoDB multi-condition query in Java. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template