mgo search based on datetime

29 views
Skip to first unread message

vineet daniel

unread,
Mar 4, 2016, 8:00:32 AM3/4/16
to mgo-...@googlegroups.com
Hello,

I need to search documents from a collection based upon datetime i.e using $lt and $gt, I am storing date in this format ISODate("2015-12-31T06:45:49.832Z")

and my query is like this 

str := r.FormValue("date")
t, err1 := time.Parse(time.RFC3339, str)


iter := uc.session.DB("dbname").C("posts").Pipe([]bson.M{bson.M{"$match": bson.M{"rupdatedon": bson.M{"$lt": t}}},
{"$lookup": bson.M{"from": "users", "localField": "userid", "foreignField": "_id", "as": "user_details"}},
bson.M{"$sort": bson.M{"rupdatedon": 1}},
bson.M{"$limit": l}}).Iter()

but the results that I am getting are based upon date and not time. i.e if i search for documents which are less than rupdatedon (2015-12-31T06:45:49.832Z) I get all the results for 31-12-2015.

Sorry for bothering you guys again, but need help with this.

Regards
Vineet Daniel
Cell          : +918527565696
Websites : 
Blog   |   Linkedin  |  Twitter

Gustavo Niemeyer

unread,
Mar 4, 2016, 8:39:55 AM3/4/16
to mgo-...@googlegroups.com
Hi Vineet,

Can you provide a tiny self-contained example of the issue?  We should be able to run it with "go run" and be able to identify the problem.

With that it should be easy to give you a hand on it. 

--
You received this message because you are subscribed to the Google Groups "mgo-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mgo-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Reply all
Reply to author
Forward
0 new messages