.net - Using MongoDB in C#, how do I derive a TimeSpan from a value in a record? -


this work:

var mycollection = collection.where(r =>                     r.channelid == channelid &&                     r.type == resourcetype.redundancylock &&                     r.groupid == groupid &&                     (r.ownerid == "" ||                      r.ownerid == ownerid ||                      r.lastupdatetime < datetime.utcnow.subtract(timespan.fromseconds(r.timedelta)))); 

sadly, results in exception:

    "unsupported clause: (r.lastupdatetime < (nullable<datetime>)datetime:(2014-08-18t20:26:44.6861998z).subtract(timespan.fromseconds((double)r.timedelta)))." 

the following query works:

var mycollection = collection.where(r =>                         r.channelid == channelid &&                         r.type == resourcetype.redundancylock &&                         r.groupid == groupid &&                         (r.ownerid == "" ||                          r.ownerid == ownerid ||                          r.lastupdatetime < datetime.utcnow.subtract(timespan.fromseconds(10)))); 

is there way can derive timespan value of record?

the answer 2 stage query. filter there clause as can.

var hold = collection.where(r =>                 r.channelid == channelid &&                 r.type == resourcetype.redundancylock &&                 r.groupid == groupid); 

then pull down data server

var holdlist = hold.tolist(); 

then use last query

return holdlist.where(r =>   (r.ownerid == "" ||          r.ownerid == ownerid ||          r.lastupdatetime < datetime.utcnow.subtract(timespan.fromseconds(r.timedelta)))); 

it less optimal because pulling more database need. , also, you're using more memory on web server otherwise. end result should work.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -