public
Created

  • Download Gist
gistfile1.py
Python
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
from mongoengine import Document, StringField, ReferenceField, BooleanField
 
class A(Document):
a = StringField()
 
 
class B(Document):
b = StringField()
boolfield = BooleanField(default=False)
ref = ReferenceField(A)
 
 
A1 = A(a='abcde')
A1.save()
<A: A object>
 
A2 = A(a='xyz')
A2.save()
<A: A object>
 
B11 = B(b='bcd', ref=A1)
B11.save()
<B: B object>
 
B12 = B(b='bbb', boolfield=True, ref=A1)
B12.save()
<B: B object>
 
B21 = B(b='zzz', ref=A2)
B21.save()
<B: B object>
 
B22 = B(b='yyy', boolfield=True, ref=A2)
 
B22.save()
<B: B object>
 
a_query = A.objects(a='abcde')
a_query
[<A: A object>]
 
b_query = B.objects(ref__in=a_query)
b_query
[<B: B object>, <B: B object>]
 
b_query_bool = b_query.filter(boolfield=True)
b_query_bool
gistfile2.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
/dev/mongoengine/queryset.pyc in __repr__(self)
1968 for i in xrange(REPR_OUTPUT_SIZE + 1):
1969 try:
-> 1970 data.append(self.next())
1971 except StopIteration:
1972 break
 
/dev/mongoengine/queryset.pyc in next(self)
1013 return self._get_as_pymongo(self._cursor.next())
1014
-> 1015 return self._document._from_son(self._cursor.next())
1016 except StopIteration, e:
1017 self.rewind()
 
/dev/mongoengine/queryset.pyc in _cursor(self)
605 if self._cursor_obj is None:
606
--> 607 self._cursor_obj = self._collection.find(self._query,
608 **self._cursor_args)
609 # Apply where clauses to cursor
 
 
/dev/mongoengine/queryset.pyc in _query(self)
387 def _query(self):
388 if self._mongo_query is None:
--> 389 self._mongo_query = self._query_obj.to_query(self._document)
390 if self._class_check:
391 self._mongo_query.update(self._initial_query)
 
/dev/mongoengine/queryset.pyc in to_query(self, document)
208
209 def to_query(self, document):
--> 210 query = self.accept(SimplificationVisitor())
211 query = query.accept(QueryTreeTransformerVisitor())
212 query = query.accept(QueryCompilerVisitor(document))
 
/dev/mongoengine/queryset.pyc in accept(self, visitor)
259 self.children[i] = self.children[i].accept(visitor)
260
--> 261 return visitor.visit_combination(self)
262
263 @property
 
/dev/mongoengine/queryset.pyc in visit_combination(self, combination)
78 if all(isinstance(node, Q) for node in combination.children):
79 queries = [node.query for node in combination.children]
---> 80 return Q(**self._query_conjunction(queries))
81 return combination
82
 
/dev/mongoengine/queryset.pyc in _query_conjunction(self, queries)
96
97 query_ops.update(ops)
---> 98 combined_query.update(copy.deepcopy(query))
99 return combined_query
100
 
/usr/lib/python2.7/copy.pyc in deepcopy(x, memo, _nil)
161 copier = _deepcopy_dispatch.get(cls)
162 if copier:
--> 163 y = copier(x, memo)
164 else:
165 try:
 
/usr/lib/python2.7/copy.pyc in _deepcopy_dict(x, memo)
255 memo[id(x)] = y
256 for key, value in x.iteritems():
--> 257 y[deepcopy(key, memo)] = deepcopy(value, memo)
258 return y
259 d[dict] = _deepcopy_dict
 
/usr/lib/python2.7/copy.pyc in deepcopy(x, memo, _nil)
188 raise Error(
189 "un(deep)copyable object of type %s" % cls)
--> 190 y = _reconstruct(x, rv, 1, memo)
191
192 memo[d] = y
 
/usr/lib/python2.7/copy.pyc in _reconstruct(x, info, deep, memo)
332 if state:
333 if deep:
--> 334 state = deepcopy(state, memo)
335 if hasattr(y, '__setstate__'):
336 y.__setstate__(state)
 
/usr/lib/python2.7/copy.pyc in deepcopy(x, memo, _nil)
161 copier = _deepcopy_dispatch.get(cls)
162 if copier:
--> 163 y = copier(x, memo)
164 else:
165 try:
 
/usr/lib/python2.7/copy.pyc in _deepcopy_dict(x, memo)
255 memo[id(x)] = y
256 for key, value in x.iteritems():
--> 257 y[deepcopy(key, memo)] = deepcopy(value, memo)
258 return y
259 d[dict] = _deepcopy_dict
 
/usr/lib/python2.7/copy.pyc in deepcopy(x, memo, _nil)
172 copier = getattr(x, "__deepcopy__", None)
173 if copier:
--> 174 y = copier(memo)
175 else:
176 reductor = dispatch_table.get(cls)
 
/envs/alwaysdata/lib/python2.7/site-packages/pymongo/collection.pyc in __call__(self, *args, **kwargs)
1401 self.__name)
1402 raise TypeError("'Collection' object is not callable. If you meant to "
1403 "call the '%s' method on a 'Collection' object it is "
1404 "failing because no such method exists." %
-> 1405 self.__name.split(".")[-1])
TypeError: 'Collection' object is not callable. If you meant to call the '__deepcopy__' method on a 'Collection' object it is failing because no such method exists.

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.