the creation of simple data sets mongodb

2010-12-27  来源:本站原创  分类:Database  人气:87 

1. Document-Oriented (for documents)
MongoDB is a document-oriented (document-oriented) database, which is stored in a JSON-like structured data. Although the ownership and relational database Database / Table similar to the DB / Collection concept, but within the same Document Collection can have different properties.
(Note: The following> prompt indicates that the mongo JS code,>>> to Python code)
> Use blog
switched to db blog

> Db.users.insert ({name: "user1", age: 15})
> Db.users.insert ({name: "user2", age: 20, sex: 1})

> Db.users.find ()
{"_id": ObjectId ("4c479885089df9b53474170a"), "name": "user1", "age": 15}
{"_id": ObjectId ("4c479896089df9b53474170b"), "name": "user2", "age": 20, "sex": 1}

$ Exists by the existence of a field judge.
> Db.users.find ({sex: {$ exists: true}})
{"_id": ObjectId ("4c479896089df9b53474170b"), "name": "user2", "age": 20, "sex": 1}

2. Embed vs. Reference (VS traditional relational database embedded in the relationship reference)
This Document to JSON-like hierarchical structure, so we can use the embedded (Embed) instead of the traditional relational database associated reference (Reference).
> U = db.users.findOne ({name: "user1"})
{
"_id": ObjectId ("4c479885089df9b53474170a"),
"Name": "user1",
"Age": 15
}

> U.address = ["address1", "address2"]
["Address1", "address2"]

> Db.users.save (u)

> Db.users.findOne ({name: "user1"})
{
"_id": ObjectId ("4c479885089df9b53474170a"),
"Name": "user1",
"Age": 15,
"Address": [
"Address1",
"Address2"
]
}

> Db.users.findOne ({address: "address1"})
{
"_id": ObjectId ("4c479885089df9b53474170a"),
"Name": "user1",
"Age": 15,
"Address": [
"Address1",
"Address2"
]
}
MongoDB support "." Separated namespace path, but the key does not need to pay attention to "$" at the beginning, can not contain "." Characters (conditional expression of the multi-path must use the quotation marks).
> U = db.users.findOne ({address: "address1"})
{
"_id": ObjectId ("4c479885089df9b53474170a"),
"Name": "user1",
"Age": 15,
"Address": [
"Address1",
"Address2"
]
}

> U.im = {MSN: " [email protected] ", QQ: 12345678}
{"MSN": " [email protected] "," QQ ": 12345678}

> Db.users.save (u)

> U = db.users.findOne ({"im.qq": 12345678})
{
"_id": ObjectId ("4c479885089df9b53474170a"),
"Name": "user1",
"Age": 15,
"Address": [
"Address1",
"Address2"
],
"Im": {
"MSN": " [email protected] ",
"Qq": 12345678
}
}

> U.im.qq
12345678

> U.im.msn
[email protected]

> Db.users.update ({"im.qq": 12345678}, {$ set: {"im.qq": 12345}})

> U = db.users.findOne ({"im.qq": 12345})
{
"_id": ObjectId ("4c479885089df9b53474170a"),
"Name": "user1",
"Age": 15,
"Address": [
"Address1",
"Address2"
],
"Im": {
"MSN": " [email protected] ",
"Qq": 12345
}
}

> U = db.users.find ({"im.qq": {$ exists: true}}, {"im.qq": 1})
{"_id": ObjectId ("4c479885089df9b53474170a"), "im": {"qq": 12345}}

Note: Because each document contains the complete key data, key as short as possible can save storage space.

相关文章
  • the creation of simple data sets mongodb 2010-12-27

    1. Document-Oriented (for documents) MongoDB is a document-oriented (document-oriented) database, which is stored in a JSON-like structured data. Although the ownership and relational database Database / Table similar to the DB / Collection concept,

  • mongodb simple data sets to create 2010-12-27

    1. Document-Oriented (document-oriented) MongoDB is a document-oriented (document-oriented) database, it is stored within a JSON-like structured data. Although the ownership and relational database Database / Table similar to DB / Collection concept,

  • BI Note: incremental approach to multi-dimensional data sets 2010-03-23

    Transfer from the following: http://www.cnblogs.com/aspnetx/archive/2009/09/24/1573513.html This will simulate a data warehouse system, including user data, product data and order data. Based on these data structures to establish multi-dimensional da

  • MapReduce: Super simple data processing on a cluster 2010-11-27

    Abstract MapReduce is a programming model, and processing, resulting in large data sets related to implementation. The user to specify a map function takes a key / value pairs, resulting in the middle of the key / value pairs. And then specify a redu

  • Oracle database, large data sets the type of settings in the result set 2010-07-13

    Oracle database in the case of large data sets, the result set can not be set to scrollability. Or will cause a lot of byte array can not be GC, leading to memory overflow. Can not use conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, Res

  • The input of the byte unit, said the most simple data 2010-08-31

    / ** * Based on the input byte units, calculated that the most simple data * For example, 1024 was 1k * / function humanReadableSize (f_size) ( return getSmartSize (f_size); ) function getSmartSize (f_size) ( var funit, k_size, m_size, g_size, f_size

  • Android SharedPreferences simple data storage class and examples of Detailed (through the "Remember Password" feature to learn SharedPreferences) 2011-01-05

    SharedPreferences is the Android simple data stored in a utility class. Imagine it is a little Cookie, it is by using a key on the way to the simple data types (boolean, int, float, long, and String) stored in the application's private directory (dat

  • Using built-in data sets easily debug Offic 2011-04-14

    Design reports using the reporting tool, there is always met some of their own can not solve the problem, so the reporting tool vendors need to consult technical support. Support those who say most often is: the report sent to me see it. But the repo

  • Using built-in data sets easily account statements debugging Bo 2011-04-17

    Design reports using the reporting tool, there is always met some of their own can not solve the problem, so the reporting tool vendors need to consult technical support. Support those who say most often is to report to me to see it. But the report t

  • Use built-in data sets easily debug RAQ Report 2011-04-14

    Use reporting tools designed to report the time, there will always encounter some can not solve their own problems, so the reporting tool vendors need to consult technical support. Technical support to those most often say is this: to report to me to

  • spring mvc3 increase productivity - using annotation data sets before and after the interaction to be more transparent 2010-05-29

    Spent time this week get a look at spring mvc3, intends to organize a cheatsheet out, easy to quickly get started later. Services to the client-side data Back page, Controller of method returns String, String location corresponding to the view that i

  • MySQL Master / Slave simple data synchronization mechanism 2010-10-24

    MySQL, Master / Slave synchronization mechanism by which the data is so simple, its principle is open in the Master binary log function (log-bin = "log-file-name"), this function will record data for any operation (create, insert , update, etc.)

  • The data structure mongodb 2010-12-27

    MongoDB document structure: mongodb data structure for the db -> collection -> data can be understood as a relational database db database collection can be understood as the table data for the element, that is, objects or documents (can be nested..

  • MySQL Master / Slave synchronization mechanism to achieve simple data 2010-10-24

    The MySQL Master / Slave synchronization mechanism so that data has become so simple, the principle is the Master on binary logging (log-bin = "log-file-name"), this function will record data for any operation (create, insert , update, etc.), th

  • Spring Data与MongoDB:不协调的设计 2014-02-10

    MongoDB是一款非常知名的NoSQL文档数据库,而Spring则是Java领域著名的开源框架.除了构成Spring核心的IoC与AOP之外,Spring也有大量应用于各个不同领域的子框架,其中Spring Data就是专门针对数据处理的一个子项目.在Spring Data下有Spring Data JPA.Spring Data MongoDB.Spring Data Redis等子项目,从名字就可以看出来这些子项目所针对的目标.其中,Spring Data MongoDB是专门针对Mong

  • 再说一下 坑爹的spring data jpa + mongodb + shiro的配置问题 2015-04-01

    接上篇文章 http://my.codeweblog.com/longyuan/blog/392219 新需求来了 要加入shiro 来保护站点安全 配置ing 配置ing 略 幸福的等待启动: 10:16:08.237 ERROR c.q.c.w.l.ApplicationContextPostListener[121] - error detail: org.springframework.beans.factory.BeanCreationException: Error creating

  • FastReport studio dynamically load data sets 2010-05-20

    FastReport studio dynamic loading test data set used in FastReport Studio version 4.6.80 First reference FastReport.dll Then the C: \ Program Files \ FastReports \ FastReport Studio Trial \ Examples \ VisualC #. NET \ DataSetDemo directory FrxDataSet

  • PostgreSql simple data types (PostgreSql Study Notes 4) 2010-11-17

    Table 8-2. Numeric type Name Storage space Description Range smallint 2 bytes Small integer -32768 To +32767 integer 4 bytes Common integer -2147483648 To +2147483647 bigint 8 bytes A wide range of integer -9223372036854775808 To 9223372036854775807

  • Preference of simple data storage android 2010-12-01

    In fact, here is the persistence of local configuration file read and write, to achieve is by Activity.getPreferences (int) to get SharedPreferences object, and then read and write operation of the configuration file, it is worth noting that the foll

  • Compare the two data sets are equal 2011-07-20

    (Select * from wms_pick_ticket minus select * from wms_pick_ticket ) union all (Select * from wms_pick_ticket minus select * from wms_pick_ticket ) If there are different lists of data