Last active
November 18, 2015 15:35
-
-
Save sepehr/0e4608c6ed0f02523288 to your computer and use it in GitHub Desktop.
MongoDB: Remove an array from an embedded document
This file contains hidden or 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
// | |
// Find documents with sub-document query: | |
// | |
db.collection_name.find({ | |
relays: { | |
$elemMatch: { | |
timestamp: {$gte: 1447628400}, | |
status: "RELAY_STATUS_ERROR_SUBMIT", | |
app_id: ObjectId("537cb1b5fc20a0eb47000000") | |
} | |
} | |
}).pretty(); | |
// | |
// Remove subdocument from an embedded array: | |
// | |
db.collection_name.update( | |
// Matches parent document: | |
{ | |
relays: { | |
$elemMatch: { | |
timestamp: {$gte: 1447628400}, | |
status: "RELAY_STATUS_ERROR_SUBMIT", | |
app_id: ObjectId("537cb1b5fc20a0eb47000000") | |
} | |
} | |
}, | |
// Removes sub-document from the embedded array: | |
{ | |
$pull: { | |
relays: { | |
timestamp: {$gte: 1447628400}, | |
status: "RELAY_STATUS_ERROR_SUBMIT", | |
app_id: ObjectId("537cb1b5fc20a0eb47000000") | |
} | |
} | |
}, false, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment