pymongo


python motor offers fetch_next exception on aggregation


I'm having difficulty with Motor's aggregation function giving a no fetch_next exception
The code is
cursor = db[collection].aggregate(myPipeline, cursor = {} )
if (yield cursor.fetch_next):
obj = bson.json_util.dumps(cursor.next_object())
self.write(obj)
that burped up the following
Exception: :'TracebackFuture' object
has no attribute 'fetch_next'
Then I tried the following that was found in a SO question
cursor = yield motor.Op(db[collection].aggregate, x_query)
that offered the same exception.
Running the aggregate in Mongo shell produces a bonafide result
"result" : [
{
"_id" : "Adam",
"num" : 110
},
{
"_id" : "Argyle",
"num" : 77
},
{
"_id" : "Net Valley",
"num" : 67
},
{
"_id" : "Notts Farm",
"num" : 64
},
{
"_id" : "Sam's Place",
"num" : 59
},
{
"_id" : "Tilly",
"num" : 58
},
{
"_id" : "Xavier",
"num" : 52
}
],
"ok" : 1
Motor has offered no such issue with find and `find_one. In fact, it works awesome otherwise.
Installation was done via pip install motor on Ubuntu.
Cheers
I'm sorry, the documentation is wrong. "aggregate" returns a Future, and you must yield the Future to get a cursor:
cursor = yield db[collection].aggregate(myPipeline, cursor={})
if (yield cursor.fetch_next):
obj = bson.json_util.dumps(cursor.next_object())
self.write(obj)
I've assigned myself a ticket, MOTOR-34, to track this issue for the next release.

Related Links

Pymongo error : 'Cursor' object has no attribute 'find' , how to filter it?
Spark Streaming: foreachRDD insert into mongoDB using python?
how to find right version of bson from pip for pymongo/mongoengine
How to enable `projection` in pymongo query class `find()`?
Variables don't hold value for very long pymongo ipython
pymongo upgrade to 3.0.3 causes this statement to fail
UUID to NUUID in Python
how to test for empty mongodb query in pymong
read video file from mongodb with pymongo
Get OperationFailure error with PyMongo 2.7.1
Inserting string as regular string in mongodb
Mongos + Pymongo 2.5 ==>No suitable hosts found
pymongo collection add item using update
How to convert objectid to string
Conditional atomic mongo remove with different results
python script to connect to mongodb master

Categories

HOME
mod-rewrite
adfs3.0
jms
workflow
applescript
mongoid
fogbugz
fedora
javafx-8
static-analysis
cocotb
sharepoint-online
eddystone
wine
erd
phpstorm-2017.1
clish
pygobject
asciimath
exe
google-sites
checkout
jaspersoft-studio
adminlte
yii2-basic-app
kamailio
websphere-portal
substring
sybase-ase
web-config-transform
ipa
onchange
unmarshalling
location-services
quick-nimble
epplus
formsauthenticationticket
redgate
spinner
code-rally
iscroll
windows-store
grails-spring-security
newtons-method
xcode8.2
android-webservice
asp.net-web-api-routing
portability
sesame
annotatorjs
yui3
openseadragon
dpkg
noclassdeffounderror
processor
jemdoc
arbre
largenumber
extend
artisan
flow-js
scala-macros
mxe
microsoft-expression-web
juttle
osascript
siena
category-theory
senchatouch-2.4
map
lru
void-pointers
eager-loading
arel
oscilloscope
days
background-thread
linkbutton
towers-of-hanoi
platform-independent
uploading
mmc3
3des
eventaggregator
rawcontacts
data-retrieval
community-server
rootkit

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App