Date query with ISODate not working in MongoDB

128 views
Skip to first unread message

Manoj P T

unread,
May 1, 2015, 2:24:24 AM5/1/15
to mongod...@googlegroups.com
I am using MongoDb-3.0.1.

"DATE" : ISODate("2015-04-30T07:40:49.064Z") //This is how date is stored in database.

db.coll.find({DATE:{$gte: ISODate("2015-04-29T08:06:11.049Z")}}) in Mongo Shell is working fine.

coll.find(new BasicDBObject("DATE", new BasicDBObject("$gte", date))); in Java is working fine.


But I am not able to execute the same when I store the function in system.js.

I stored aggregation functions in system.js and tried to execute these from Java:


     db.coll.aggregate([{$match:{DATE:{$gt:date}}}]);
     db.eval("somefunction1(ISODate(\""+ date+"\")");   //date is in the form "2015-04-29T11:31:36.426Z"

     db.coll.aggregate([{$match:{DATE:{$gt:date}}}]);
     db.eval("somefunction2("+date+")"); //date is in the form "Wed Apr 29 11:31:36 IST 2015"

     db.coll.aggregate([{$match:{DATE:{$gt: new Date(date.toISOString()) }}}]); 
     db.eval("somefunction2("+date+")"); //date is in the form "Wed Apr 29 11:31:36 IST 2015"
     


It is not working for me. Could any one help me.

Asya Kamsky

unread,
May 1, 2015, 8:14:13 AM5/1/15
to mongodb-user

Since db.eval is being deprecated, I would recommend against using it.

Is there a reason you're trying to use this via function rather than just making a regular query?

Asya

--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: http://www.mongodb.org/about/support/.
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at http://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/e263549d-b45c-4276-a21d-967fc6f3a313%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Manoj P T

unread,
May 1, 2015, 8:46:50 AM5/1/15
to mongod...@googlegroups.com
I could do that directly from Java. I have stored aggregation functions (for analytics purpose which we want to run as a batch process) in system.js collection.  Is it not recommende to use db.eval() ?? Then what is alternative to user functions in system.js collection ???

Asya Kamsky

unread,
May 1, 2015, 9:36:44 AM5/1/15
to mongodb-user

I wouldn't recommend storing aggregations in the server system.js - i would just treat it like the rest of your code and keep it there.

Asya

Message has been deleted

Manoj P T

unread,
May 1, 2015, 9:42:50 AM5/1/15
to mongod...@googlegroups.com
I stored aggregation functions in system.js and called from Java and then did some manipulation over the aggregation output.  So what is the correct approach to to this?? In what cases stored functions would be helpful??
Reply all
Reply to author
Forward
0 new messages