Search
 
SCRIPT & CODE EXAMPLE
 

SHELL

import csv into mongodb

mongoimport --type csv -d database -c collection --headerline --drop index2020.csv
Comment

mongodb export to csv

mongoexport --host localhost --db dbname --collection name --csv --out text.csv --fields firstName,middleName,lastName
Comment

import csv to MongoDB

import pandas as pd
from pymongo import MongoClient
import json

def mongoimport(csv_path, db_name, coll_name, db_url='localhost', db_port=27000)
    """ Imports a csv file at path csv_name to a mongo colection
    returns: count of the documants in the new collection
    """
    client = MongoClient(db_url, db_port)
    db = client[db_name]
    coll = db[coll_name]
    data = pd.read_csv(csv_path)
    payload = json.loads(data.to_json(orient='records'))
    coll.remove()
    coll.insert(payload)
    return coll.count()
Comment

PREVIOUS NEXT
Code Example
Shell :: how to start xampp in ubuntu from terminal 
Shell :: cp folders 
Shell :: command to update ubuntu 
Shell :: get first line of output bash 
Shell :: bash tokens in variable 
Shell :: change default php alternatives 
Shell :: taskkill linux 
Shell :: docker image rm image without tag 
Shell :: install fleetssl 
Shell :: git revert pr merge 
Shell :: batch multiline command 
Shell :: command to stop a system service 
Shell :: remove last commit 
Shell :: react-native-router-flux 
Shell :: applescript copy to clipboard 
Shell :: ffmpeg to mkv 
Shell :: github restore previous commit 
Shell :: can not ping github 
Shell :: bash for i in range 
Shell :: powershell script enable tls 1.2 
Shell :: git alias - multiple commands 
Shell :: ldap query powershell 
Shell :: install rest framework django command ubuntu 
Shell :: delete a github repository using bash 
Shell :: create new ssh key for github 
Shell :: anaconda install package 
Shell :: push a branch with diffrent name 
Shell :: how to install portainer on raspberry pi 
Shell :: Finding path to some ruby versions 
Shell :: apt-get ana-conda 
ADD CONTENT
Topic
Content
Source link
Name
6+2 =