MongoDB Dot-Notation Query

I'm new to MongoDB, and I'm having trouble getting my point notation requests to work ...

I am using pymongo with MongoDB running on a remote instance of Amazon EC2 ...

Instead of writing massive XML parsing code to extract a lot of different data, I convert XML to JSON, dumping everything into MongoDB, and then trying to extract pieces of data that I want to use with point queries ...

Data is converted to JSON and pasted into Mongo fine. I see all the inserts (from the python shell) ...

for an element in db.feed.find (): element

Here is an example that returns ...

   {u'timestamp': datetime.datetime(2010, 11, 8, 20, 19, 55, 87000), u'message': u'{"category": {"text": "Scores"}, "XML_File_ID": {"text": "12292403"}, "game": {"status": {"text": "4 Qtr", "attrib": {"numeral": "4", "type": "P"}}, "time_r": {"text": "10:01"}, "vscore": {"text": "27"}, "vteam": {"text": "Pittsburgh", "attrib": {"id": "082"}}, "hteam": {"text": "Cincinnati", "attrib": {"id": "064"}}, "hscore": {"text": "14"}}, "seasontype": {"text": "Regular"}, "schedule_id": {"text": "3151"}, "location": {"city": {"text": "Pittsburgh"}, "state": {"text": "PA"}, "country": {"text": "USA"}}, "time_stamp": {"text": " November 8, 2010, at 11:19 PM ET "}, "game_id": {"text": "3151"}, "sport": {"text": "NFL"}, "heading": {"text": "BC-ABP+082:064* 27 14 4R10:01"}}', u'_id': ObjectId('4cd8cbebe8b5d58527000016')}

So, I am trying to make such a request, but I am not getting any results ...

db.feed.find_one ({"message.category.text": "Scores"})

What is the correct way to execute queries of this type and return the entire document in response? Thank!

+3
source share
3 answers

I tested these queries both inside the MongoDB shell and using pymongo and they work for me. Do you forget to save the results in a variable and / or print them?

0
source

I would suggest looking into $ elemmatch if you often look at subdocment queries.

"Using the query operator $ elemMatch (mongod> = 1.3.1), you can map the entire document inside the array."

Read more here: white papers and blog post ...

0
source

json- (u '). , XML JSON .

 u'message:u'{category:{text:"scores"}
0

Source: https://habr.com/ru/post/1773887/


All Articles