I’m using the official C# mongodb driver, and it does have LINQ support. But I’m having trouble trying to convert this to use the php driver.
This is the LINQ query:
.Where(c => DateTime.UtcNow.Subtract(c.DateRequested).TotalDays <= 14).Where(d => ((d.itemid == req.itemid) && (d.MediaType == req.MediaType)) && (d.Status != RequestStatus.Cancelled))
I’m not 100% sure how if I’m going about this correctly but this is my attempt so far in readable format:
Array
(
[$and] => Array
(
[DateRequested] => Array
(
[$gt] => MongoDate Object
(
[sec] => 1341754027
[usec] => 0
)
[$lte] => MongoDate Object
(
[sec] => 1342963627
[usec] => 0
)
)
[$and] => Array
(
[$and] => Array
(
[itemid] => 76510
[MediaType] => 0
)
[Account] => Josh
)
[Status] => Array
(
[$ne] => 3
)
)
)
And here is the messy form:
array('$and' => array('DateRequested' => array('$gt' => new MongoDate((time() - 1209600)), '$lte' =>new MongoDate(time())),'$and' => array('$and' => array('itemid' => $itemid,'MediaType' => $source),'Account' => $account),'Status' => array('$ne' => 3)))
Not sure if I’ve inferred your correct document structure from the code examples above, but assuming a test document added in the
mongoshell similar to:An example search in PHP might look like:
Note that the query elements are implicitly using “and” criteria. Where the same field needs to be repeated (eg.
DateRequested), an explicit$andis required so the field keys are distinct.