Created
          August 26, 2023 23:41 
        
      - 
      
- 
        Save DiracSpace/29280285f1e4d071a166313464558b45 to your computer and use it in GitHub Desktop. 
    Script for importing multiple collections in JSON format into MongoDB using CLI
  
        
  
    
      This file contains hidden or 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 | |
| find -- *.json | sed 's/.json$//' | while read -r col; do | |
| echo "importing $col" | |
| mongoimport -d edgraph -c "$col" --file "$col.json" --jsonArray | |
| done | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Sometimes exporting a collection from MongoDB adds the database prefix into the name. So, if you want to obtain the collection name from the filename containing the prefix
database_name.collection_nameyou can do the following: