mongodb - pymongo如何提取按数据库中document字段存储顺序存储的所有key。
漂亮男人
漂亮男人 2017-05-02 09:24:29
0
2
900

RT.
最近在做数据预处理方面的东西,想在代码里用一个list来存放所有的key,然后通过传入指定column的下标来提取相应条目的字段信息。最好list中key的顺序固定,比如mongodb中document存储key的顺序。由于find_one等相关方法返回的是dict类型,所以是乱序,想问下有什么方法提取所有的key并按其在数据库中存储的顺序存放?

漂亮男人
漂亮男人

reply all(2)
迷茫

It should be noted that the definition of key-value pairs in JSON is inherently unordered, and the database does not guarantee the order in which BSON objects will be stored. So don't rely on this order for anything.

某草草

Try this:

  1. Set a key list and a tool for generating OrderDict;

  2. Deposit into mongo normally;

  3. Query the results and use the above "Tool to generate OrderDict" to generate an OrderDict instance object.

I don’t know if this can meet your needs. But if your object needs to be transmitted using methods such as JSON, the order may be messed up again.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!