Advertisement
Guest User

Untitled

a guest
Aug 21st, 2017
782
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. > db.properties.findOne({'agentid':'mike@gmail.com'},{'agentid':1,'contact':1})
  2. {
  3. "_id" : ObjectId("56d2cc296f07d417008b4567"),
  4. "agentid" : "mike@gmail.com",
  5. "contact" : [
  6. {
  7. "type" : "listingAgent",
  8. "id" : "1",
  9. "name" : "Mike",
  10. "telephoneType" : "",
  11. "telephone" : "",
  12. "email" : "mike@gmail.com"
  13. }
  14. ]
  15. }
  16.  
  17. > db.agents.findOne({'email':'mike@gmail.com'})
  18. {
  19. "_id" : ObjectId("5979d1400045fecc0800004c"),
  20. "id" : "35",
  21. "agentID" : "mike@gmail.com",
  22. "email" : "mike@gmail.com",
  23. "name" : "Mike",
  24. "telephone" : "",
  25. "status" : true
  26. }
  27.  
  28. > db.users.findOne({'email':'mike@gmail.com'})
  29. {
  30. "_id" : ObjectId("5979d0e20045feac0d00003f"),
  31. "id" : "20",
  32. "email" : "mike@gmail.com",
  33. "type" : "publisher",
  34. "status" : "inactive",
  35.  
  36.  
  37. }
  38.  
  39. $query =
  40. array(
  41. array('$lookup'=>array(
  42. 'from'=>'agents`',
  43. 'localField'=>'email',
  44. 'foreignField'=>'email',
  45. 'as'=>'users_agents'
  46. )
  47. ),
  48.  
  49. array('$unwind'=>'$properties.contact'),
  50.  
  51. array('$lookup'=>array(
  52. 'from'=>'properties',
  53. 'localField'=>'email',
  54. 'foreignField'=>'contact.email',
  55. 'as'=>'users_properties'
  56. )
  57. ),
  58.  
  59.  
  60. array('$match'=>array(
  61. '$and'=>array(array('users_properties.offline'=>false),
  62. array('users_agents.status'=>true)))),
  63.  
  64.  
  65. array('$project'=>array(
  66. '_id'=>1,
  67. 'id'=>1,
  68. 'username'=>1,
  69. 'firstname'=>1,
  70. 'lastname'=>1,
  71. 'email'=>1,
  72. 'type'=>1,
  73. 'status'=>1,
  74. )
  75. ),
  76.  
  77. );
  78.  
  79. $collection_users->aggregate ($query );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement