0

次の問題があります。Pymongo は本来よりも少ないフィールドを返します。

これが私のクエリです: db.users.findOne({'e.email': 'xxx@gmail.com', application: 'App1'})

mongo dbから直接取得します: { "_id" : ObjectId("51803128e4b092fd00c8899b"), "application": "App1", "d" : ISODate("2013-04-30T21:01:28.084Z"), "e" : [ { "email" : "xxx@gmail.com", "isValidated" : true } ], "fn" : "XXX", "l" : "en_US", "ln" : YYY", "si" : [ { "isTokenExpired" : true, "oAuth" : { "value" : "", "permissions" : [ ] }, "sIden" : { "id" : "123", "network" : 0 } } ], "tz" : "Etc/UTC" }

しかし、pymongo は同じクエリで "si" 配列を返さず、フィールド ln,fn は空です:

query = collection.find_one({'e.email': 'xxx@gmail.com', application: 'App1'})
print query

[{u'application': 'App1', u'tz': u'Etc/UTC', u'd': datetime.datetime(2013, 4, 30, 22, 52, 45, 916000), u'ln': u'', u'l': u'en_US', u'e': [{u'isValidated': True, u'email': u'xxx@gmail.com'}],u'_id': ObjectId('51804b3de4b092fd00c88d1b'), u'fn': u''}]

何の問題?ありがとう!

4

1 に答える 1

1

PyMongoでは、1 つのドキュメントのみを返すfindOneを呼び出しています。一方、MongoDB に対してネイティブにクエリを実行している場合は、findOne を呼び出していないため、より多くの結果が得られます。結果から、クエリをネイティブに作成するためにfind()を使用していることは明らかです。MongoDB の公式ドキュメントによると、 findOnefindの違いは次のとおりです。

findOne()
One document that satisfies the query specified as the argument 
to this method. If the projection argument is specified, the 
returned document contains only the projection fields, and the _id
field if you do not explicitly exclude the _id field.

find()
A cursor to the documents that match the query criteria. 
If the projection argument is specified, the matching
documents contain only the projection fields, and the _id
field if you do not explicitly exclude the _id field.
于 2013-04-30T23:30:25.837 に答える