Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Search by date & tags in mongodb java

Tags:

java

mongodb

What are the different options for search by date & tags using java & mongodb?

What are the steps that should I keep in mind for storing dates & tags into mongo using java?

like image 725
Roshan B Vishwakarma Avatar asked Apr 30 '26 00:04

Roshan B Vishwakarma


2 Answers

There should be nothing special about searching for dates over any other type of data. You can use comparators so you can search across date ranges for example. Any tags that you want to query on will obviously benefit from indexing so you might want to setup a multiple single indexes on these fields.

http://cookbook.mongodb.org/patterns/date_range/

Another question here about storing tag data and querying on it which goes into more detail.

Datastore solution for tag search

like image 181
DeliveryNinja Avatar answered May 01 '26 13:05

DeliveryNinja


Here is following code for select a value from the mongodb with java. Hope it will help you.

MongoClient mongo=new MongoClient("localhost",27017);
DB db = mongo.getDB("yourdb");
DBCollection coll=db.getCollection("yourtable");
BasicDBObject doc1=new BasicDBObject("email",email).
           append("password", password); 
DBCursor cours=coll.find(doc1);
if(cours.hasNext())
   {
       Map userdata=cours.next().toMap();
       String username=userdata.get("username").toString();  
       String email1=userdata.get("email").toString(); 
       }
like image 44
Simmant Avatar answered May 01 '26 13:05

Simmant



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!