If I understood well, you would like to pass the
`force_autorefs_current_db` only some time
but not all the time.
So, I expect you want something like that :
event_doc = con.db.col.EventDocument(force_autorefs_current_db=True).find_one(...)
is that right ?
To what object this `__iter__` method is attached ?
If I understood well, you would like to pass the
`force_autorefs_current_db` only some time
but not all the time.
So, I expect you want something like that :
event_doc = con.db.col.EventDocument(force_autorefs_current_db=True).find_one(...)
is that right ?
def test_simple_mapreduce(self):
class MyDoc(Document):
structure = {
'user_id': int,
}
self.connection.register([MyDoc])
for i in range(20):
self.col.MyDoc({'user_id':i}).save()
class MapDoc(Document):
"""
document which handle result of map/reduce
"""
structure = {
'value':float,
}
self.connection.register([MapDoc])
m = 'function() { emit(this.user_id, 1); }'
r = 'function(k,vals) { return 1; }'
mapcol = self.col.map_reduce(m,r)
mapdoc = mapcol.MapDoc.find_one()
assert mapdoc == {u'_id': 0.0, u'value': 1.0}, mapdoc
assert isinstance(mapdoc, MapDoc)
The example below shows how to work with map/reduce and dbref :
def test_mapreduce_with_dbref_force_autorefs_current_db(self):
class MyDoc(Document):
structure = {
'user_id': int,
}
self.connection.register([MyDoc])
for i in range(20):
self.col.MyDoc({'_id':'bla'+str(i), 'user_id':i}).save()
m = 'function() { emit(this.user_id, 1); }'
r = 'function(k,vals) { return {"embed":{"$ref":"mongokit",
"$id":"bla"+k}}; }'
class MapDoc(Document):
use_autorefs = True
force_autorefs_current_db = True
structure = {
'value':{
"embed":MyDoc,
}
}
self.connection.register([MapDoc])
mapcol = self.col.map_reduce(m,r)
mapdoc = mapcol.MapDoc.find_one()
assert mapdoc == {u'_id': 0.0, u'value': {u'embed': {u'_id':
u'bla0', u'user_id': 0}}}
assert isinstance(mapdoc, MapDoc)
It is what you want ? You can do query easily :
results = mapcol.MapDoc.find( my_complex_query )
The example below shows how to work with map/reduce and dbref :