简体   繁体   English

Mongoengine:为什么to_json返回$ oid或$ date键?

[英]Mongoengine : Why to_json return $oid or $date key ?

Using python and mongodb with mongoengine, I wonder why "to_json" function doesn't work as excepted. 结合使用mongoengine和python和mongodb,我想知道为什么“ to_json”功能无法正常运行。

For exemple,with "Comments" as a Document, comments. 例如,以“评论”作为文档,进行评论。 to_json() returns me : to_json()返回我:

  {
  "_id": {
    "$oid": "53eb97a312f8035580b92241"
  },
  "created": {
    "$date": 1407955862027
  }

And I except to get : 我除了得到:

  {
  "_id":"53eb97a312f8035580b92241",
  "created": 1407955862027
  }

Do I really need to parse all the json data to get what I want ? 我真的需要解析所有json数据才能得到我想要的吗?

JSON supports simple datatypes only and as such there is no native JSON support for ObjectId's or for dates. JSON仅支持简单数据类型,因此不存在对ObjectId或日期的本地JSON支持。 BSON the binary json supertype that MongoDB stores its data in has support for more datatypes. BSON MongoDB将数据存储在其中的二进制json超类型具有对更多数据类型的支持。

To allow lossless BSON -> JSON -> BSON conversion there is an extended json format and this is what MongoEngine uses. 为了允许无损BSON-> JSON-> BSON转换,存在扩展的json格式 ,这就是MongoEngine使用的格式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM