我有一个我没有创建的Mongo数据库或架构师,是否有一种很好的方法来反省数据库或打印出结构是什么,以开始处理存储什么类型的数据,数据类型是如何嵌套的等等?
br3*_*3w5 31
只需在mongo shell中运行以下命令即可查询数据库:
use mydb //this switches to the database you want to query
show collections //this command will list all collections in the database
db.collectionName.find().pretty() //this will show all documents in the database in a readable format; do the same for each collection in the database
Run Code Online (Sandbox Code Playgroud)
然后,您应该能够检查文档结构.
Sam*_*aye 23
实际上有一个工具可以帮助你在这里叫做Variety:
http://blog.mongodb.org/post/21923016898/meet-variety-a-schema-analyzer-for-mongodb
你可以在这里查看Github回购:https://github.com/variety/variety
我应该警告你:
因此,我建议您在开发服务器或副本的隐藏节点上运行它.
根据文档的大小和深度,可能需要很长时间来理解数据库的粗略结构,但最终会给出一个.
我建议限制结果集,而不是发出不受限制的find命令.
use mydb
db.collectionName.find().limit(10)
var z = db.collectionName.find().limit(10)
Object.keys(z[0])
Object.keys(z[1])
Run Code Online (Sandbox Code Playgroud)
这将有助于您了解您的数据库结构或缺乏数据库结构.
这将打印名称及其类型
var schematodo = db.collection_name.findOne()
for (var key in schematodo) { print (key, typeof key) ; }
Run Code Online (Sandbox Code Playgroud)
小智 5
一种选择是使用Mongoeye。它是类似于 Variety 的开源工具。
不同的是 Mongoeye 是一个独立的程序(不需要 Mongo Shell)并且具有更多的功能(直方图、最频繁值等)。
https://github.com/mongoeye/mongoeye
几天前,我发现 GUI 客户端MongoDB Compass具有一些不错的可视化效果。请参阅产品概述。它直接来自 mongodb 人员,根据他们的文档:
MongoDB Compass 旨在让用户轻松分析和理解 MongoDB 中数据集合的内容...
| 归档时间: |
|
| 查看次数: |
60049 次 |
| 最近记录: |