Home >Java >javaTutorial >Implementation case of mongoDB multi-condition query in Java

Implementation case of mongoDB multi-condition query in Java

黄舟
黄舟Original
2017-09-25 10:39:572736browse

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)

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>

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!

Statement:
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