Is there a way through the c# driver to pull the timestamp out of the
_id value and query using it?
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
Is there a way through the c# driver to pull the timestamp out of the
_id value and query using it?
I have a collection of logged events, and make use of the _id time
stamp. Not sure how you read it on the 10gen driver, but to do a search,
I wrote a C# extenstion, to convert the DateTime to an _id. Then use
that in your queries.
private static readonly DateTime Epoch = new DateTime(1970, 1, 1,
0, 0, 0, DateTimeKind.Utc);
public static byte[] ToMonGo_id(this DateTime date)
{
byte[] _id = new byte[12];
byte[] secs = BitConverter.GetBytes((UInt32)new
TimeSpan(date.Ticks - Epoch.Ticks).TotalSeconds);
Array.Reverse(secs);
Array.Copy(secs, _id, 4);
return _id;
}