Developers tips&tricks - Gapminder/dollar-street-framework GitHub Wiki
Mongo authentication database
Mongo saves users in one of its databases. The authentication database for current environments is dollarstreet
. So you might have to user --authenticationDatabase=dollarstreet
in some cli commands, when you don't specify the database as dollarstreet
and in GUI apps like MongoDB Compass.
Update incomes from PROD to DEV DB:
- export PROD DB
db.places.find()
.projection({income: 1, name: 1})
- export DEV DB
db.places.find()
.projection({income: 1, name: 1})
or instead use
mongoexport --collection=places --jsonArray --out=places.json --fields=income,name -u=[username] -p=[password] -d=dollarstreet
to export incomes from a database
- open lodash.com
- create function ObjectId(value) {return value;}
- put all from PROD dump to
var test = [];
- put all from DEV dump to
var test2 = [];
- check differences
- create bulk update for update all Places or/and other collections
const result = _.reduce(test, (result, item) => {
const matchedItem = _.find(test2, [ "_id", item._id ]);
if (!_.isEmpty(matchedItem) && matchedItem.income !== item.income) {
const id = matchedItem._id;
const income = matchedItem.income;
result.push(`{ updateOne: { filter: {_id: ObjectId("${id}")}, update: { $set: { income: ${income} } } } }`);
}
return result;
}, []);
console.log(`db.places.bulkWrite([${result.join(',\n')}] )`);
- restore updated DB to DEV DB