This article mainly introduces how python reads json files and inserts data into mongodb. it analyzes Python's skills in operating json and mongodb databases, for more information about how to read json files and insert data to mongodb
The example in this article describes how Python reads the JSON file and inserts the data into MongoDB. Share to everyone for your reference. The implementation method is as follows:
#coding =utf-8import sunburntimport urllibfrom pymongo import connectionfrom bson.objectid import Objectidimport Loggingfrom datetime
This article describes how Python reads a JSON file and inserts data into MongoDB. Share to everyone for your reference. The implementation method is as follows:
#coding =utf-8 import sunburnt import urllib from Pymongo import Connection from Bson.objectid
tank -c users --csv -f uid,name,sex -o tank/users.csv connected to: 127.0.0.1 exported 4 records
4, according to the conditions to dare to out data?
123
[[emailprotected] mongodb]# mongoexport -d tank -c users -q ‘{uid:{$gt:1}}‘ -o tank/users.json connected to: 127.0.0.1 exported 3 records
Mongoimport Import a table, or some field in a table1, Common command forma
Label:After converting data from HDFS to JSON format, the file name of the 10 files is filename _01 .... _02. 03 format. Write a simple sh file with the i+1 file name corresponding to the-do loop-the path of the file names to be passed in and the data files that need to be imported when executing, so that they can be passed in to facilitate the project to change the directory.. sh Files:However, there is no confusion! Discover./mongo-h 10.1.235.62-por
Tags: using strong file Data SP on C R databaseMongoDB database is also inseparable from the necessary maintenance, such as backup, recovery, import, export.In fact, backup and recovery is easier than import and export, and generally does not make mistakes, so most of the time using backup and recovery operations.1. Back Up MongoDBMongodump-h ruiyip-d Dataname-o/home/aa/dev/
Mongoexport--help Export Parameter Help
Mongoimport--help Import Parameters Help
Summarize:
Mongoexport--host 172.20.41.xx--username--port xxx xxx--password 1234--db cmpdb--collection wangzs-f name-o E:\wan Gzs.datMongoimport--host 172.20.41.xx--port xxx--username xxx--password 1234--db cmpdb--collection wangzstemp E:\wangzs.dat
The exported Wangzs.dat file is in JSON format, which includes the _id fiel
implemented to backup and restore the database, the file format is JSON and Bson. Unable to refer to a table backup or restore. Four, Mongoexport export the table, or some fields in the table 1, Common command format The above parameters are good to understand, focus on:-F export refers to field, split by font size,-f name,email,age export name,email,age three fields-Q can export the root query condition,-Q ' {"UID": "100"} ' exports the data with
How to import MongoDB data into hive.
Principle:
By default, any table created in Hive is hdfs-based; That's, the metadata and underlying rows of data associated with the table are stored in HDFS. Mongo-hadoop now supports the creation of mongodb-based Hive tables and bson-based tables. Both mongodb-based Hive tables a
]#/mongoexport-d my_mongodb-c user--csv-f Uid,username,age-oUser_csv.datConnected to:127.0.0.1Exported 2 records[email protected] bin]# cat User_csv.datUid,username,age2, "Jerry", 1001, "Tom", 25[Email protected] bin]#Parameter description:-csv means to export to CSV format-F indicates which examples need to be exportedMore detailed usage can be mongoexport–help to seeData import MongoimportIn the previous example we discussed the use of the export to
,username,age-o User_csv.dat Connected to:127.0.0.1Exported 2 records[Root @localhost bin]# cat User_csv.datUid,username,age2, "Jerry", 1001, "Tom", 25[Email protected] bin]#Parameter description:-csv means to export to CSV format-F indicates which examples need to be exportedMore detailed usage can be mongoexport–help to seeData import Mongoimport In the previous example we discussed the use of the export tool, and this section will discuss how to
[-- collection] arg collection to use (some commands)-- Objcheck validate object before inserting(Default)-- Noobjcheck don't validate object before inserting-- Filter arg filter to apply before inserting-- Drop each collection before import-- OplogReplay replay oplog for point-in-time restore-- OplogLimit arg include oplog entries beforeProvided Timestamp (seconds [: ordinal])During the oplog replay; the ordinalValue is optional-- KeepIndexVersi
"--csv-o/root/test.csv
Export data based on criteria:
Copy Code code as follows:
# mongoexport-d Yourdb-c yourcoll-q ' {score:{$gt: '} '-o/root/yourcoll-bk.json
More Mongoexport Detailed
Collection Data Import-mongoimport
To restore the exported collection data:
Copy Code code as follows:
# mongoimport-d Yourdb-c Yourcoll--file/root/yourcoll.json
Import
Tags: style color os io file data CTI LineStart by generating a text file that can be either JSON or CSV, one per line of data, well organized, and can be generated in a generic text editor or from office. Then execute the following import command: /usr/local/mongodb/bin/mongoimport-d cms-c cms_tags_20120727–type csv–file/tmp/tag0810.csv-h localhost-port 111 11–u
Tags: mongod database BSP backup file export save files--useExport of databasesmongoexport-d database name-C collection name----Save address of export file and save file name. JSON--type JSONImport of databasesmongoimport-d database name-C collection name--file the file address and filename to prepare for import. JSON--type JSONPS: The Chinese in the command is c
Some things are recorded and will be used again soon.1. Updating complex nested objects from MongoDB to SOLRRecently using Mongo-connector to open MongoDB with SOLR, for simple JSON, update is no problem. The problem we have this time is that if the value of one field in JSON is an array type, or if there is an object
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.