Last active
June 7, 2016 18:11
-
-
Save mwmahlberg/3c8b73f500b83aca491652b625711e53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Data | |
{ | |
"_id" : ObjectId("5744753e97bfc8000a18e3b2"), | |
"breeds" : [ | |
"pomeranian" | |
], | |
"colors" : [ | |
"apricot" | |
], | |
"delinquent" : false, | |
"isDeleted" : false, | |
"weight" : 10, | |
"name" : "Zoloft", | |
"deletionReason" : null, | |
"species" : null, | |
"sex" : "spay", | |
"birth" : null, | |
"owner" : ObjectId("5413490f3a31c400077d6c8d"), | |
"microchip" : null, | |
"deletedBy" : null, | |
"jurisdiction" : "Jo Davies", | |
"deletionDate" : null, | |
"vaccinations" : [ | |
{ | |
"type" : "1 year rabies", | |
"user_id" : "https://api.stormpath.com/v1/accounts/3aUTDjDnVxNIz6nfgA6iuW", | |
"vetName" : "Alan Schroeder", | |
"nextVac" : ISODate("2017-06-02T05:00:00Z"), | |
"org_id" : ObjectId("5750895384736c00099a4e97"), | |
"organization" : "Mt. Carroll Veterinary Clinic", | |
"pet" : ObjectId("5744753e97bfc8000a18e3b2"), | |
"date" : ISODate("2016-06-02T05:00:00Z"), | |
"_id" : ObjectId("5750895384736c00099a4e98") | |
} | |
], | |
"registrations" : [ | |
{ | |
"tagNumber" : "%%%%%", | |
"type" : "1 year", | |
"nextReg" : ISODate("2017-05-26T05:00:00Z"), | |
"lifetime" : false, | |
"pet" : ObjectId("5744753e97bfc8000a18e3b2"), | |
"_id" : ObjectId("5747d038a303b70009e22d88"), | |
"user_id" : "https://api.stormpath.com/v1/accounts/3aUTDjDnVxNIz6nfgA6iuW", | |
"date" : ISODate("2016-05-26T05:00:00Z"), | |
"organization" : "Jo Davies", | |
"org_id" : ObjectId("5747d038a303b70009e22d87"), | |
"microchip" : "!!!!!!!!!!!" | |
}, | |
{ | |
"type" : "1 year", | |
"user_id" : "https://api.stormpath.com/v1/accounts/3aUTDjDnVxNIz6nfgA6iuW", | |
"org_id" : ObjectId("5750895c84736c000a01d7e0"), | |
"organization" : "Carroll County", | |
"microchip" : "315145", | |
"tagNumber" : "12346", | |
"pet" : ObjectId("5744753e97bfc8000a18e3b2"), | |
"date" : ISODate("2016-06-02T05:00:00Z"), | |
"_id" : ObjectId("5750895c84736c000a01d7e1"), | |
"lifetime" : false, | |
"nextReg" : ISODate("2017-06-02T05:00:00Z") | |
} | |
] | |
} | |
# query w/ $elemMatch | |
db.dogs.find({ | |
"registrations": { | |
"$elemMatch": { | |
"date" : { | |
"$gte": new ISODate("2016-06-01T01:00:00Z"), | |
"$lt": new ISODate("2016-06-06T05:00:00Z") | |
} | |
} | |
} | |
},{ | |
_id:0, | |
registrations:{ | |
"$elemMatch": { | |
date:{ | |
"$gte": new ISODate("2016-06-01T01:00:00Z") | |
} | |
} | |
} | |
}).pretty() | |
# Return value | |
{ "_id" : ObjectId("540e116bb209ca5198c247cf") } | |
# Desired Return value | |
"registrations" : [ | |
{ | |
"type" : "1 year", | |
"org_id" : ObjectId("5750895c84736c000a01d7e0"), | |
"organization" : "Carroll County", | |
"tagNumber" : "12346", | |
"pet" : ObjectId("5744753e97bfc8000a18e3b2"), | |
"date" : ISODate("2016-06-02T05:00:00Z"), | |
} | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment