Advertisement
Guest User

Aggregate Commands for Redmart Addresses

a guest
Jan 24th, 2021
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. db.members.aggregate([
  2. {$unwind: "$addresses"},
  3. {$project: { _id: 0, first_name: {$replaceAll: {input: {$toLower: "$addresses.first_name"}, find: " ", replacement: ""}}, last_name: {$replaceAll: {input: {$toLower: "$addresses.last_name"}, find: " ", replacement: ""}}, postcode: "$addresses.postcode" }},
  4. {$out: "aggregate_addresses"}
  5. ])
  6.  
  7. db.members.aggregate([
  8. {$unwind: "$credit_cards"},
  9. {$project: { _id: 0, first_name: {$replaceAll: {input: {$toLower: "$credit_cards.billing_address.firstname"}, find: " ", replacement: ""}}, last_name: {$replaceAll: {input: {$toLower: "$credit_cards.billing_address.lastname"}, find: " ", replacement: ""}}, postcode: "$credit_cards.billing_address.postal_code" }},
  10. {$merge: {into: "aggregate_addresses"}}
  11. ])
  12.  
  13. .\mongoexport --db redmart --collection aggregate_addresses --out addresses.json
  14.  
  15. db.addresses.ensureIndex({first_name:1,last_name:1,postcode:1},{unique:true})
  16.  
  17. .\mongoimport.exe --db redmart --collection addresses --file .\addresses.json
  18.  
  19. Count: 1275267
  20.  
  21. # https://research.reignofcomputer.com/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement