python - Adding JSON like documents to a new collection Pymongo -
So I have just asked for an existing archive for some documents that are all tags: "_t": "blanket". After these documents, I want to include it in a new collection that is designed to keep these types of documents with usernames (like usernames_connection data).
So here is my code:
#import to import module OS, pymongo, datetime import datetime Conn = None db = none json isConnected = false # try MongoDB connecting to server: Conn = pymongo.MongoClient () db = conn.emmersiv # emmersiv db been connected printer connected to db.collection_names () "MongoDB server" emmersiv db print within archive files #Print isConnected = Except the truth: Print "connection fails ..." in a list and then all the collections #get filters the '' 'for users in ALLUSERS Kinect Data The username '' non-user data ALLUSERS = db.collection_names remove (): coll = pymongo.collection.Collection (db, users.lower ()) print "are currently looking at in", Users.lower (), "Konekt data can filter made to" # all skeletal data # ectData = coll.find ({ "_ T": "SkeletonJoints"}) newColl = users.lower () + a new collection of "_kinectData" #name and try putting all Kinect data in a new collection to be #try: Coll.find (for line { '_ t': 'Skeletnjints'}): print line jsonObj = json.loads (line) #JSON To the converts ? If jsonObj No: #create collection db.create_collection (newColl) #and insert JSON document coll.insert (jsonObj) an entry to the finished print "entry", newColl print "", pymongo.errors. New Collection: Except Collection Pymongo.errors 'Collection', new call, 'already exists' except CollectionInvalid. Operation Failure: Print "----> OP entry has failed" pymongo.errors.InvalidName: Print "----> Excluding Invalid Entry Name": Print "---- & gt; WTF? ", Traceback.print_exc () So my problem is when I try to insert, nothing is being inserted. I do not really understand why this does not work. I'm trying again through the cursor .....
Thank you for your help!
There is no need to change JSON: PyMongo reads BSON from MongoDB and drops into dragon dicts , And when you pass it into a dragon dict PyMongo BSON and send it to MongoDB. JSON never joins.
There is no need to call create_collection, Mongo DB creates a collection when you first include it.
Your statement will be retrieved from the current collection, with the value " Skettenjoint "is a field with" _t ", so I look at it that there is no such document present? Have you made the following efforts in Mongo Shell:
& gt; Emmersive & gt; Use Db.MY_COLLECTION.find ({_t: "SkeletonJoints"}) I hope that if you do this query (by changing "MY_COLLECTION" by the name of a real archive ) You will not find any documents in the Mongo shell.
Comments
Post a Comment