MongoDB Table Structure Analysis Tool Introduction--Variety

Source: Internet
Author: User

Today, we introduce a software to analyze the structure of MONGODB database table--varity. For MongoDB This schema free database, the software comes with the query collection stored in the data situation is difficult to see the specific data structure at a glance, Tomá Dvoák authors write a variety.js script that makes it easy to understand the data structure in a collection. The author hosts the tool on GitHub and welcomes anyone to provide advice or add functionality. The following variety features are translated from the author's blog:


The collection information output format is ASCII.

    • You can see clearly what type of data format each key uses

    • You can see how much of a key is used in this collection.

    • Limit the number of documents that can be queried

    • Can limit the depth of query documents

    • You can analyze only a subset of documents

    • You can sort the results of a query

    • Can save query results

    • Can be output in JSON format

    • Tool introduction Easy to use, no other library dependencies

Variety's https://github.com/variety/variety.


How to use:


MONGO database_name--eval "var collection = ' Coll_name '" variety.js, such as my database_name is test, Coll_name is the users,


The data I inserted beforehand is

Db.users.insert ({name: "Tom", Bio: "A nice guy.", Pets: ["monkey", "fish"], Someweirdlegacykey: "I like ike!"}); Db.users.insert ({name: "Dick", Bio: "I swordfight.", Birthday:new Date ("1974/03/14")});d B.users.insert ({name: "Harry" , Pets: "Egret", Birthday:new Date ("1984/03/14")});d B.users.insert ({name: "Shanker", Bio: "A VA?"});


Normal Query The echo of users is like this

> db.users.find () {  "_id"  : objectid ("56CFC28FBDAE9B9A922A19CB"),  "name"  :   "Tom",  "bio"  :  "A nice guy",  "pets"  : [   "monkey",    "Fish"  ],  "Someweirdlegacykey"  :                                                                                           "i like ike!"  }{  "_id"  : objectid ("56cfc2acbdae9b9a922a19cc"),  "name"  :  "Dick",  " Bio " : " i swordfight. "  }{  "_id"  : objectid ("56cfc2c6bDAE9B9A922A19CD "), " name " : " Harry ", " Pets " : " Egret " }{ " _id " :  objectid ("56cfc2e0bdae9b9a922a19ce"),  "name"  :  "Shanker",  "bio"  :  "Caca"  }


This is the result of the variety query.

mongo test --eval  "var collection =  ' users '"  variety.jsmongodb shell  version: 2.4.9connecting to: testVariety: A MongoDB Schema  analyzerversion 1.5.0, released 14 may 2015using collection of  "Users" Using query of { }using limit of 4using maxdepth of 99using  sort of {  "_id"  : -1 }Using outputFormat of  "ASCII" Using  persistResults of falseUsing resultsDatabase of  "Varietyresults" using  resultscollection of  "Userskeys" using resultsuser of nullusing resultspass  of nullusing plugins of [ ]+--------------------------------------------------------- -----------+| key                 | types                | occurrences  | percents | |  ------------------ | -------------------- | ----------- | -------- | |  _id                |  ObjectId             |            4 |    100.0 | |  name               |  string               |            4 |    100.0 | |  bio                |  string               |            3 |     75.0 | |  pets               |  string  (1),array  (1)  |           2  |     50.0 | |  someWeirdLegacyKey | String                |           1 |      25.0 |+--------------------------------------------------------------------+

is the format very friendly and easy to read?


If the database is not using the default port, you can use the--port parameter:

MONGO database_name--port 27111--eval "var collection = ' Coll_name '" variety.js


If the db file is not in the default file, you can use the--dbpath parameter:

MONGO database_name--dbpath/path/to/database/folder--eval "var collection = ' Coll_name '" variety.js


If you need to sort the query, you can use this:

MONGO database_name--eval "var collection = ' Coll_name ', sort = {date:-1}" variety.js


This can be used if the output format of the JSON is required:

MONGO database_name--eval "var collection = ' users ', OutputFormat = ' json '" variety.js


If a collection has 1 billion data, we can limit the number of queries, using limit to qualify:


MONGO database_name--eval "var collection = ' users ', limit = +" Variety.js

If a colletions has too many layers nested, you can use maxdepth to limit the query:


Db.users.insert ({name: "Walter", Somenestedobject:{a:{b:{c:{d:{e:1}}}});
[[email protected]:~/variety04:05] $mongo  test --eval  ' var collection =  ' Users '    variety.jsmongodb shell version: 2.4.9connecting to: testvariety:  A MongoDB Schema AnalyzerVersion 1.5.0, released 14 May  2015using collection of  "Users" using query of { }using limit of  5Using maxDepth of 99Using sort of {  "_id"  : -1 }using  outputFormat of  "ASCII" using persistresults of falseusing resultsdatabase  of  "Varietyresults" using resultscollection of  "Userskeys" Using resultsuser  of nullusing resultspass of nullusing plugins of [ ]+----------- -----------------------------------------------------------------+| key                         | types                 | occurrences |  percents | |  -------------------------- | -------------------- | ----------- | --------  | |  _id                         | ObjectId              |           5  |    100.0 | |  name                        | String                |           5 |    100.0 | |  bio                         | String                |           3  |     60.0 | |  pets                        | String  (1),array  (1)  |            2 |     40.0 | |  someNestedObject           | Object                |             1 |     20.0 | |  someNestedObject.a         | Object                |            1 |     20.0 | |  someNestedObject.a.b       | Object                |            1 |     20.0 | |  someNestedObject.a.b.c     | Object                |            1 |     20.0 | |  someNestedObject.a.b.c.d   | Object               |            1 |     20.0 | |  someNestedObject.a.b.c.d.e | Number                |           1  |     20.0 | |  someWeirdLegacyKey         | String                |            1 |     20.0 |+------------------------------ ----------------------------------------------+[[email protected]:~/variety05:06] $mongo  test -- eval  "var collection =  ' users ',  maxdepth = 3"  variety.jsMongoDB shell version: 2.4.9connecting to: testvariety: a mongodb schema  analyzerversion 1.5.0, released 14 may 2015using collection of  "Users" Using query of { }using limit of 5using maxdepth of 3using  sort of {  "_id"  : -1 }Using outputFormat of  "ASCII" Using  persistResults of falseUsing resultsDatabase of  "Varietyresults" using  resultscollection of  "Userskeys" using resultsuser of nullusing resultspass  of nullusing plugins of [ ]+--------------------------------------------------------- -------------+| key                   | types                 | occurrences | percents | |  -------------------- | -------------------- | ----------- | --------  ||  _id                   | objectid             |            5 |    100.0 | |  name                  | string               |            5 |    100.0 | |  bio                   | String               |           3 |      60.0 | |  pets                  | String  (1),array  (1)  |            2 |     40.0 | |  someNestedObject     | Object                |            1 |     20.0 | |  someNestedObject.a   | Object                |           1  |     20.0 | |  somenestedobject.a.b | object               |            1 |     20.0 | |  someWeirdLegacyKey   | String                |           1  |     20.0 |+------------------------------------------------------------------- ---+


If you need to set conditions for a query, such as Carddabout to True, you can:

MONGO database_name--eval "var collection = ' Coll_name ', query = {' Caredabout ': true}" variety.js

It should be noted that variety in the analysis of the data structure, the actual use of MapReduce to do, the full table scan operation, so if the analysis of the online library, it is advisable to use a non-service backup repository or low-peak business. Avoid pressure on your online business.



Reference Address:

Http://www.acetolyne.net/Projects7/node/48

Https://github.com/variety/variety

http://www.mongoing.com/archives/2282



This article is from "Tianya Horizon" blog, please be sure to keep this source http://shanker.blog.51cto.com/1189689/1745258

MongoDB Table Structure Analysis Tool Introduction--Variety

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.