MONGODB CONNECTION QUERY

35 views
Skip to first unread message

ADITYA PATEL

unread,
Jan 19, 2017, 1:52:08 AM1/19/17
to mongodb-dev
HII ALL ,

     I HAVE A QUERY THAT I WANT A MONGODB CONNECTION PROGRAMME IN THAT I WANT TO CONNECT TO THE MONGO SHELL AS WE CAN DIRECTLY CONNECT THROUGH MONGODB SO CONNECTION AND I WANT TO IMPORT THE JSON FILE THROUGH PROGRAMME NOT THROUGH MONGO SHELL SO AND FIRE A MONGODB QUERY  THROUGH PROGRAMME SO CAN ANYONE GUIDE ME THROUGH THIS PROBLEM ANY LANGUAGE IS ACCEPTED EITHER C OR PYTHON

THANKING YOU,
ADITYA

A. Jesse Jiryu Davis

unread,
Jan 19, 2017, 8:07:45 AM1/19/17
to mongodb-dev
If you have a file called "data.json" of JSON documents, one per line, like this:

{"_id": {"$oid": "5880b85da08bff41ba63449e"}, "a": {"$numberLong": "123"}, "b": 1.0}
{"_id": {"$oid": "5880b85da08bff41ba63449f"}, "a": {"$numberLong": "432"}, "b": 2.0}

... then you can insert it into a collection with a Python program like this:

from bson import json_util
from pymongo import MongoClient

client = MongoClient()
db = client.test

db.collection.remove({})  # Delete existing data.

for line in open('data.json'):
    db.collection.insert_one(json_util.loads(line))

This list is for discussion of MongoDB project development/contribution (as well as development of related drivers and tools).  In the future, if you have a question about using MongoDB please post the question in the mongodb-user forum.  

Aditya Talaviya

unread,
Jan 19, 2017, 10:55:01 AM1/19/17
to mongo...@googlegroups.com
THANK YOU CAN U GIVE ME YOUR MAIL ID SO I CAN ASK YOU FURTHER  QUIRES

--
You received this message because you are subscribed to a topic in the Google Groups "mongodb-dev" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mongodb-dev/SS3ouJNNs8s/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mongodb-dev+unsubscribe@googlegroups.com.
To post to this group, send email to mongo...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-dev.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-dev/25b76811-3c0d-4e51-8240-adada0ab852a%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages