I have a Python3 application which inserts movie information into a mongodb back-end (MongoDB Compass), and a separate nodejs application which returns it.
this was working fine, however i cleared the DB out and re-ran the application, now when I insert a document with insert_one
the structure returned is always lost:
query = {
"Name": name,
"Year": year,
"Format": definition,
"Extension": extension,
"Filepath": filepath,
"MD5Hash": filehash,
"Subtitles": subtitles,
"Date": date,
"FileSize": size
}
result = db.Movies_test.insert_one(query)
first run returned data:
_id: 5b1470da91cb5a2240c57c43
Extension: "mkv"
Format: "1080p"
Filepath: "E:\Movies\10 Cloverfield Lane [2016] 1080p.mkv"
Year: "2016"
FileSize: 2953397031
MD5Hash: "baf1b857c3f2f4fe6d08161e814a64c2"
Date: 2018-06-03 23:51:06.503
Subtitles: false
Name: "10 Cloverfield Lane"
UpdateTime: 2018-06-04 00:42:51.141
second run returned data:
_id: 5b80322f91cb5a05a809a70f
Year: "2016"
FileSize: 2953397031
Format: "1080p"
Filepath: "E:\Movies\10 Cloverfield Lane [2016] 1080p.mkv"
Date: 2018-08-24 17:28:31.067
Name: "10 Cloverfield Lane"
Extension: "mkv"
MD5Hash: ""
Subtitles: false
I noticed a similar question here: { $t: “”, $v: “”} structure in MongoDB collections using pymongo however there is no solution, the user just switched to using DocumentDB.
I read that insert
has an extra option insert(query, {'ordered': True})
, but this also does not keep the data structure:
_id: 5b80373691cb5a10c42c5906
Subtitles: false
Format: "1080p"
FileSize: 2953397031
Extension: "mkv"
Date: 2018-08-24 17:49:58.160
Name: "10 Cloverfield Lane"
MD5Hash: ""
Filepath: "E:\Movies\10 Cloverfield Lane [2016] 1080p.mkv"
Year: "2016"
Any help would be great, and ideally I would prefer to insert in the original query order, instead of processing the output when its comes out of nodejs.