Comments (19)
@hiroaki-yamamoto I discovered my error.
I did not append .get()
method when retrieving objects
#only returns referenced document object ids
user = User.objects(id=ObjectId("57e968198d84c00035c82c63"))
return jsonify(json.loads(user.to_json()))
#returns referenced complete document as embedded document
user = User.objects(id=ObjectId("57e968198d84c00035c82c63")).get()
return jsonify(json.loads(user.to_json()))
from mongoengine-goodjson.
This feature is very helpful. Thanks.
from mongoengine-goodjson.
Perhaps, I think your document schema (i.e. class that inherits Document
or EmbeddedDocument
) inherits mongoengine.Document
and mongoengine.EmbeddedDocument
and they disallow follow_reference
kwargs.
from mongoengine-goodjson.
Done, but there's a missing line on coverage.
from mongoengine-goodjson.
Hi @macfire,
Do you mind if you tell me what db
and gj
are?
from mongoengine-goodjson.
I used factory pattern to init flask_mongoengine (potential problem?)
#extensions.py:
from flask_mongoengine import MongoEngine
db = MongoEngine()
#myapp.py
db.init_app(app)
#models.py
from myapp.extensions import db
import mongoengine_goodjson as gj
from mongoengine-goodjson.
Ok,
How about using gj.FollowReferenceField
, not db.FollowReferenceField
?
from mongoengine-goodjson.
Sorry for the confusion, I miss-wrote the example above.
My actual code is using gj.FollowReferenceField
(I've changed the example above to reflect this)
from mongoengine-goodjson.
Oh... ok
However, this smells like a bug because I expected FollowReference should work on QuerySet as well as Document.
from mongoengine-goodjson.
@hiroaki-yamamoto You may close this issue, unless you want to leave it open in regards to the bug.
from mongoengine-goodjson.
Please leave as-is, because it needs investigation. If you don't want "many messages", plese unsubscribe.
from mongoengine-goodjson.
Note
- queryset.py line 22 doesn't seem to support following reference and
as_pymongo
returns "dicts" in a list. And filtering the fields that is typed asFollowReferenceField
and ReferenceField. - For
from_json
, perhaps it seems to be ok because queryset.py line 56 uses_from_son
, but needs tests because it is unclear.
from mongoengine-goodjson.
Branch: 15_queryset_follow_reference
from mongoengine-goodjson.
I really love this library as it makes my model class way less complex. thanks so much for your work...
I currently get a similar error when attempting to follow reference
>>> d = Drawing.objects(id='57ed40b59d1fa2ab84ea8751').get()
>>> d.to_json()
'{"strokes": [{"drawn_at": "2016-09-29T16:26:27",....
>> d.to_json(follow_reference=True)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/Users/robert/Projects/api-v2/env/lib/python3.5/site-packages/mongoengine_goodjson/document.py", line 183, in to_json
max_depth, current_depth, use_db_field, *args, **kwargs
File "/Users/robert/Projects/api-v2/env/lib/python3.5/site-packages/mongoengine_goodjson/document.py", line 66, in _follow_reference
) if doc else doc
File "/Users/robert/Projects/api-v2/env/lib/python3.5/site-packages/mongoengine/base/document.py", line 422, in to_json
return json_util.dumps(self.to_mongo(use_db_field), *args, **kwargs)
File "/Users/robert/Projects/api-v2/env/lib/python3.5/site-packages/bson/json_util.py", line 113, in dumps
return json.dumps(_json_convert(obj), *args, **kwargs)
File "/usr/local/Cellar/python3/3.5.2_3/Frameworks/Python.framework/Versions/3.5/lib/python3.5/json/__init__.py", line 237, in dumps
**kw).encode(obj)
File "/Users/robert/Projects/api-v2/env/lib/python3.5/site-packages/mongoengine_goodjson/encoder.py", line 40, in __init__
super(GoodJSONEncoder, self).__init__(*args, **kwargs)
TypeError: __init__() got an unexpected keyword argument 'current_depth'
This is on the latest branch on pypi (0.11.3).
from mongoengine-goodjson.
@leerobert Could you give me the schema?
from mongoengine-goodjson.
You're correct I am using mongoengine. I used the FollowReferenceField and had no problems with that. Unfortunately I do have some circular references so I won't be able to use that field for all of my models.
from mongoengine-goodjson.
Okay, anyway I will write test cases.
from mongoengine-goodjson.
{
u"id": text_type(reference.id),
u"name": u"test",
u"references": [article_dict.copy()],
u"ex_info": {
u"txt": reference_extra_info.txt
},
u"ex_ref": {
u"_id": {u"$oid": str(reference_extra_ref.id)},
u"ref_txt": reference_extra_ref.ref_txt
}
}
Note: I think this _id
should be id
and the id should be str, not dict.
from mongoengine-goodjson.
Closed
from mongoengine-goodjson.
Related Issues (20)
- Possibility to add model class properties in to_json()? HOT 2
- Serialization of DictField of ReferenceField HOT 11
- 2.0? HOT 1
- `DynamicField` to_json error HOT 2
- convert pipeline query result to JSON? HOT 4
- Pushing an Id to db.ListField(gj.FollowReferenceField()) adds an entire object HOT 3
- got an unexpected keyword argument 'follow_reference' HOT 1
- __unset_gj_flag_sub_field has sometimes raises error. HOT 1
- Deprecation Warning When Executing Alongside Pytest HOT 7
- Unexpected Error while saving Document in MongoEngine after using mongoengine-goodjson HOT 1
- Custom QuerySet cancels goodjson
- Dependency Dashboard
- compatibility problems HOT 2
- No ID replace when returning list of objects HOT 4
- BooleanField to python for "False" executes to True in generate_object_hook HOT 6
- Is there a way to specify which format a DatetimeField will be resolved to? HOT 3
- Documentation
- Make ID attribute the first property HOT 1
- Problem with empty list HOT 4
- Poetry HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mongoengine-goodjson.