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
#!/bin/bash | |
db=mydatabase | |
out_dir="./" | |
tmp_file="fadlfhsdofheinwvw.js" | |
echo "print('_ ' + db.getCollectionNames())" > $tmp_file | |
cols=`mongo $db $tmp_file | grep '_' | awk '{print $2}' | tr ',' ' '` | |
for c in $cols | |
do |
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
#!/bin/bash | |
host=localhost | |
db=mydatabase | |
for bson_file in `ls *.bson` | |
do | |
echo "importing $bson_file" | |
collection=$(echo "${bson_file}" | cut -d'.' -f1) | |
bson_path="$(pwd)/$bson_file" |
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
# mongo data export and import | |
mongoexport --host 10.xx.10.xx --db mydatabase --collection colln > colln.bson | |
mongoimport --host localhost --db mydatabase --collection colln colln.bson |
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
# String replacement across multiple files | |
# '' -e done for osx | |
grep -rl string1 * | xargs sed -i '' -e 's/string1/string2/g' | |
# Search (options : recursive, case insensitive, line number, directories to exclude) | |
grep -r -i -n --exclude-dir={log,tmp,config,spec} 'search-string' * |
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
use tutorial | |
db.carts.insert({ cust_id: "A123", amount: 25, status: "A", items: [ { sku: "mmm", qty: 5, price: 2.5 }, { sku: "nnn", qty: 5, price: 2.5 } ] }) | |
db.carts.insert({ cust_id: "A123", amount: 50, status: "A", items: [ { sku: "mmm", qty: 10, price: 5 } ] }) | |
db.carts.insert({ cust_id: "B212", amount: 30, status: "A", items: [ { sku: "nnn", qty: 2, price: 5 }, { sku: "kkk", qty: 1, price: 20 } ] }) | |
db.carts.insert({ cust_id: "A123", amount: 90, status: "D", items: [ { sku: "mmm", qty: 10, price: 6 }, { sku: "kkk", qty: 3, price: 10 } ] }) | |
var map = function() { | |
for(var idx = 0; idx < this.items.length; idx++) { | |
var key = this.items[idx].sku; |
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
use tutorial | |
db.orders.insert({ cust_id: "A123", amount: 500, status: "A" }) | |
db.orders.insert({ cust_id: "A123", amount: 250, status: "A" }) | |
db.orders.insert({ cust_id: "B212", amount: 200, status: "A" }) | |
db.orders.insert({ cust_id: "A123", amount: 300, status: "D" }) | |
// Calculate the sum of all “amount”s for a unique “cust_id” |
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
// Fetch average score and last answer grouped by visit_id field | |
db.feedbacks.insert({ "_id" : ObjectId("52419f0ae4b02f8c625a7ff1"), "feedback_question_id" : "52417f81e4b0b6ec25fdc988", "rater_id" : "506003b7047e9d38ee5b32ad", "merchant_id" : "52416008e4b02f4f07f78e53", "visit_id" : "52419c4ee4b07fbefee8803a", "score" : 4, "updated_at" : ISODate("2013-09-24T14:17:46Z"), "created_at" : ISODate("2013-09-24T14:17:46Z") }); | |
db.feedbacks.insert({ "_id" : ObjectId("52419f0ae4b02f8c625a7ff2"), "feedback_question_id" : "52417f88e4b0b6ec25fdc98a", "rater_id" : "506003b7047e9d38ee5b32ad", "merchant_id" : "52416008e4b02f4f07f78e53", "visit_id" : "52419c4ee4b07fbefee8803a", "score" : 4, "updated_at" : ISODate("2013-09-24T14:17:46Z"), "created_at" : ISODate("2013-09-24T14:17:46Z") }); | |
db.feedbacks.insert({ "_id" : ObjectId("52419f0ae4b02f8c625a7ff3"), "feedback_question_id" : "52417f8de4b091d72db45521", "rater_id" : "506003b7047e9d38ee5b32ad", "merchant_id" : "52416008e4b02f4f07f78e53", "visit_id" : "52419c4ee4b07fbefee8 |