3 ROOM_URI
=$
(echo $1 |
tr '[:upper:]' '[:lower:]')
4 TO_ROOM_URI
=$
(echo $2 |
tr '[:upper:]' '[:lower:]')
6 if [[ -z $ROOM_URI ]]; then
7 echo usage
$0 ROOM_URI
[TO_ROOM_URI
]
11 if [[ -z $TO_ROOM_URI ]]; then
16 mongo
--quiet localhost
/gitter
--eval "rs.slaveOk(); $1"
20 mongo
--quiet mongo-replica-02
/gitter
--eval "rs.slaveOk(); $1"
23 PROD_ROOM_ID
=$
(execute_prod
"db.troupes.findOne({ lcUri: '$ROOM_URI' }, { _id: 1 })._id.valueOf()")
25 if [[ -z $PROD_ROOM_ID ]]; then
26 echo "Unable to find room in prod"
30 DEV_ROOM_ID
=$
(execute_local
"db.troupes.findOne({ lcUri: '$TO_ROOM_URI' }, { _id: 1 })._id.valueOf()")
31 if [[ -z $DEV_ROOM_ID ]]; then
32 echo "Unable to find room in dev"
36 DEV_USER_ID
=$
(execute_local
"db.users.findOne({}, { _id: 1 })._id.valueOf()")
37 if [[ -z $DEV_USER_ID ]]; then
38 echo "Unable to find a local userid"
42 mongoexport
-h mongo-replica-02
-d gitter
-c chatmessages
-q "{ toTroupeId: ObjectId('$PROD_ROOM_ID') }" --jsonArray > /tmp
/chats.json
46 process.stdin.setEncoding('utf8');
47 process.stdin.on('data', function (d) {
50 process.stdin.on('end', function () {
51 // put all your code here
52 var array = JSON.parse(data);
53 array.forEach(function(d) {
55 d.toTroupeId.\$oid = '$DEV_ROOM_ID';
59 d.fromUserId.\$oid = '$DEV_USER_ID';
62 console.log(JSON.stringify(array))
64 process.stdin.resume();
65 " < /tmp
/chats.json
> /tmp
/chats2.json
68 mongoimport
-h localhost
-d gitter
-c chatmessages
--jsonArray < /tmp
/chats2.json