Skip to content

Instantly share code, notes, and snippets.

@Jlaird
Last active June 9, 2022 17:24
Show Gist options
  • Save Jlaird/a1418aab050bda4735d4d9700e3bff82 to your computer and use it in GitHub Desktop.
Save Jlaird/a1418aab050bda4735d4d9700e3bff82 to your computer and use it in GitHub Desktop.
List of random mongodb commands
Copy collection to another DB
db.getCollection('AdUnitPattern').find().forEach(function(d){ db.getSiblingDB('ebm_smartbuildingstech_website')['AdUnitPattern'].insert(d); });
# Clone celltion from dev to prod
db.cloneCollection("10.0.0.100", "SiteSettings")
db.cloneCollection("10.0.0.100", "AdUnitPattern")
db.cloneCollection("10.0.0.100", "Layout")
# Move collection from dev to prod
mongoexport -h 10.0.0.100 -d ebm_electronicdesign_website -c AdUnitPattern --out file
mongoimport -u developer -d ebm_electronicdesign_website -c AdUnitPattern --drop --authenticationDatabase admin --file file
mongoexport -h 10.0.0.100 -d ebm_electronicdesign_website -c Layout --out file
mongoimport -u developer -d ebm_electronicdesign_website -c Layout --drop --authenticationDatabase admin --file file
mongoexport -h 10.0.0.100 -d ebm_electronicdesign_website -c SiteSettings --out file
mongoimport -u developer -d ebm_electronicdesign_website -c SiteSettings --drop --authenticationDatabase admin --file file
// get a count to see how many match
db.getCollection('Content').aggregate([
{
$match: {
by_line: { $not: {$size: 0} }
}
},
{ $unwind: "$by_line" },
{
$group: {
_id: '$by_line',
count: { $sum: 1 }
}
},
{
$match: {
count: { $gte: 10 }
}
},
{ $sort : { count : -1} },
{ $limit : 100000 }
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment