[SERVER-17322] Different output for Mongo shell and java/python driver Created: 18/Feb/15  Updated: 19/Feb/15  Resolved: 19/Feb/15

Status: Closed
Project: Core Server
Component/s: Querying
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: sandip Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: Text File findOne.txt     Text File population.txt     Text File populationBefore.txt    
Backwards Compatibility: Fully Compatible
Operating System: ALL
Steps To Reproduce:

1. Load dataset populationBefore.txt
2. Do run findOne command. See the output . It does not looks proper output. Check the attached findOne.txt
3. Do run FInd command like db.population.find(

{"population.profile.name.first" : "CARROLL"}

)

the output is not proper.
4. From python/java driver issue the same query db.population.find(

{"population.profile.name.first" : "CARROLL"}

)

the output is different from mongoshell and not at all correct

Strange behavior.

5. I try with attached population.txt , load the data and works expected every where.

Participants:

 Description   

I have a data set , which I have attached . Now with this dataset mongodb behavior is unpredictable . I am very interested to know the reason.

Let?s for example , I load the data into mongodb :
mongoimport --db test --collection population --file populationBefore.txt --type json --jsonArray
Now when I do findOne query on this data the result is not expected. I have attached the file named findOne.txt , where you will find all JSON sub documents are same . Any reason why ?
Query within find
From pymongo module / mongojava I have tried this . When I tried the following query , result is something different

>>> post=collection.find({"population.profile.name.first" : "CARROLL"}) 
>>> for p in post:
...   print p
... 
{u'_id': ObjectId('54878c84062dfda18bcb487d'), u'population': {u'profile': {u'networth': u'428737827.60', u'siblings': u'9', u'birthday': u'1879-07-02', u'name': {u'@sex': u'f', u'last': u'SHANK', u'MI': u'P', u'first': u'AURELIO'}, u'address': {u'city': u'River Oaks ', u'zip': u'94117', u'addnum': u'1845', u'state': u'NM', u'street': u'13th Avenue ', u'@type': u'duplex'}}}}

In the result you can see no CARROLL is found .

? Same Query from Mongodb.
If I use same query with mongodb , the result is completely different . The returned document replaced all entry with NAME CARROLL and returned. While we have only one entry with name CARROLL. You will find so many CARROLL here.

mongos> db.population.find({"population.profile.name.first" : "CARROLL"})
{ "_id" : ObjectId("54dcf22100894990c1851e31"), "population" : { "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" }, "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" }, "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" }, "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" }, "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" }, "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" }, "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" }, "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" }, "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" }, "profile" : { "name" : { "@sex" : "m", "first" : "CARROLL", "MI" : "R", "last" : "DENNEY" }, "birthday" : "2010-04-05", "address" : { "@type" : "duplex", "addnum" : "45454", "street" : "Skidmore Lane ", "city" : "Center City ", "state" : "UT", "zip" : "15965" }, "siblings" : "5", "networth" : "-129768966.39" } } }
mongos>

Bothe JAVA/PYTHON driver returns different result set from mongodb .

I am very interested to know why is this behavior ? How mongodb treating things differently from java/python driver ? How mongodb stored multiple JSON object with same key ?



 Comments   
Comment by Asya Kamsky [ 19/Feb/15 ]

This would be better discussed on mongodb-user Google group.

Please note that you are connecting to mongos with mongo shell, so you should verify whether you are querying the same database, the same collection, etc.

Comment by sandip [ 19/Feb/15 ]

Thank you for the comment . My question was why then Mongoshell and java/python driver return different result set ?

Comment by Asya Kamsky [ 19/Feb/15 ]

The two files (population.txt and populationBefore.txt) have different contents. Each one has one document, in one there is a single field population and its contents are a single subdocument, the other the field population is an array of subdocuments.

In populationBefore.txt your population document has multiple subdocuments which all have the same field name:

  "population":{
      "profile":{
         },
      },
      "profile":{
         },
      },
      "profile":{
         },
      },
      "profile":{
         },
      },
      "profile":{
         },
      },
      "profile":{
         },
      },
      "profile":{
         },
      },
      "profile":{
         },
      },
      "profile":{
         },
      },
      "profile":{
         },
      }

This is not legal document, so all the profile subfields collapse into one.

Generated at Thu Feb 08 03:44:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.