meteor - How to check if a mongoDB record is less than a day old? -


i trying implement user "group" system in meteor application. here simplified example of group document mongodb structure :

{     "_id": "w74grb7gnaoqs4dmj", //id of group     "name": "my beautiful group",     "createdat": isodate("2015-05-27t12:44:52.288z"),     "createdby": "7tkqk3bm72mk47ngh",     "users": [     "7tkqk3bm72mk47ngh" //meteor user id array     ],     "admins": [     "7tkqk3bm72mk47ngh"     ],     "leaving_users": [     {     "user_id": "9zxdv6bm72mk47ngh",     "leaving_date": isodate("2015-05-27t16:15:23.170z")     }],     "modifiedat": isodate("2015-05-27t16:41:57.589z"),     "modifiedby": "fz78pr82jpz66gc3p" } 

i want obtain following behavior:

  • when user leave group, id removed group "users" array.
  • since want him able re-join group in next 24h without requesting validation group admin, create "leaving_users" array of objects 2 string fields: userid , date left.
  • if user try join again left group within 24h limit, want check if belongs leaving_users array, , if record less 24h days old.

the part have trouble server method send boolean flag meaning"has user left in past 24h". guess has mongo request can't figure out wrong.

here method code:

meteor.methods({     grouprecentlyquitted: function(groupid) {     //groups left current user in past 24h     if (users.isinroles(meteor.userid(), ["user"])) {         var yesterday = new date(new date().gettime() - (24 * 60 * 60 * 1000));         return groups.find({             _id: groupid,             "leaving_users.user_id": meteor.userid(),             "leaving_users.leaving_date": {                 $gte: yesterday             }         });     }     } }); 

and client side code call method:

var recentlyquitted = false meteor.call("grouprecentlyquitted", me._id, function(error, result) {     if (error) {     console.log("error", error);     }     if (result) {     recentlyquitted = true     console.log(result);     } }); 

this version throws rangeerror: maximum call stack size exceeded. don't why neither know how have better feedback server method execution (the error occurs during group.find query in method).

edit: query works fine in robomongo, when input directly.

ok, managed solve using answer @richsilv (if read me, thank dude). turns out can't expect cursor server method (ejson only), publish provides cursor. 3 days figure out... :-)

to summarize it, can't return collection.find() in method (i.e. cursor). need return document using collection.findone() or array of documents using collection.find().fetch()


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -