简体   繁体   中英

how do i search for an entry in mongodb database using java in netbeans?

I have made a database in Mongodb and a collection with a few entries.I want to search for an entry using Java and also display it. I'm using Netbeans as my IDE. I tried searching all over the internet but couldn't find anything relevant. I'm new to Java and Mongodb.

 DBObject result = new Mongo().getDb("yourDatabaseName").getCollection("yourTableName").findOne(new BasicDBObject("id", id), new BasicDBObject("specialColumn", 1));
return result.get("specialColumn")

This example will search for the field "specialColumn" in the collection "yourTableName" with the id "id"! There are more methods provided like .find(), where you can process with a DBCursor to check the results!

http://docs.mongodb.org/manual/tutorial/query-documents/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM