How can I get the generated query from the LINQ query? I tried this but it didnt work:
var query = (
from d in mcollection.AsQueryable<InstrumentationDocument>()
where d.user == User && d.timestamp > DateTime.Today.AddDays(-days)
orderby d.timestamp descending
select new
{
d.timestamp,
d.machine,
d.processID,
feature = d.info["feature"].AsString,
extra = d.info.Contains("extra") ? d.info["extra"].ToJson() : ""
}
);
var mongoQuery = ((MongoQueryable<InstrumentationDocument>)query).GetMongoQuery();
var json = mongoQuery.ToJson();
where InstrumentationDocument is
class InstrumentationDocument
{
[BsonId]
public ObjectId _id { get; set; }
[BsonDateTimeOptions(Kind = DateTimeKind.Local)]
public DateTime timestamp { get; set; }
public string user { get; set; }
public string machine { get; set; }
public int processID { get; set; }
public BsonDocument info { get; set; }
}
mongoQuery.ToJson()to read the value of this expression or are you writing it to a log/console? From your code example, it seems like you're not getting the query because there is no variable to read, and it's not being written anywhere.