Skip to content

Commit 7f7a757

Browse files
committed
improve highlights
1 parent c797b23 commit 7f7a757

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

_posts/2015-1-1-MongoDB-Notes.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ db.students.insert({name: "小朱"})
4646
{% endhighlight %}
4747

4848
3. 查询命令
49-
```
49+
{% highlight javascript %}
5050
值精确匹配的查询
5151
db.students.find({name: "张三"})
5252
两个条件(逻辑与)
@@ -71,7 +71,7 @@ db.students.find({school:{$exists:false}})
7171
db.students.find({name: /^小/})
7272
db.students.find({name: /.*四/})
7373

74-
```
74+
{% endhighlight %}
7575

7676
3. Update命令
7777
暂无
@@ -83,7 +83,7 @@ http://docs.mongodb.org/manual/data-modeling/
8383

8484

8585
6. 内嵌数组查询
86-
```
86+
{% highlight javascript %}
8787
db.students.insert({name: "张三", school: {name: "清华大学", city: "北京"}, courses:[{name:"MongoDB", grade:88, quiz:[9,8,9,10]},{name:"Java", grade:99,quiz:[3,2,1,5]}], age: 19, gpa: 3.97})
8888

8989
db.students.insert({name: "李四", school: {name: "北京大学", city: "北京"}, courses:[{name:"MongoDB", grade:86, quiz:[5,4,3,7]},{name:"Java", grade:92}, {name:"C++", grade:65}], age: 20, gpa: 3.3})
@@ -95,10 +95,10 @@ db.students.insert({name: "小牛", school: {name: "哈工大", city: "哈尔滨
9595
db.students.insert({name: "小马", school: {name: "交通大学", city: "西安"}, courses:[{name:"MongoDB", grade:96, quiz:[5,4,3,7]}], age: 21, gpa: 3.70})
9696

9797
db.students.insert({name: "小朱"})
98-
```
98+
{% endhighlight %}
9999

100100
7. 地理位置查询
101-
```
101+
{% highlight javascript %}
102102
db.pois.insert({name:"AAA Store", loc:{type:"Point", coordinates:[70,30]}})
103103
db.pois.insert({name:"BBB Bank", loc:{type:"Point", coordinates:[69.99,30.01]}})
104104
db.pois.insert({name:"CCC Park", loc:{type:"Polygon", coordinates:[[[70,30],[71,31],[71,30],[70,30]]]}})
@@ -135,31 +135,33 @@ db.runCommand(
135135
maxDistance: 7000
136136
}
137137
)
138-
```
138+
{% endhighlight %}
139139
9. 全文搜索
140-
```
140+
{% highlight javascript %}
141141
db.text.insert({content:"text performs a text search on the content of the fields indexed with a text index."})
142142
db.text.insert({content:"When dealing with a small number of documents, it is possible for the full-text-search engine to directly scan the contents of the documents with each query, a strategy called 'serial scanning.' This is what some rudimentary tools, such as grep, do when searching."})
143143
db.text.insert({content:"Soros enjoys playing mongo."})
144144
db.text.insert({content:"Why don't you use mongo-db?"})
145145

146-
```
146+
{% endhighlight %}
147147

148148

149149

150150
10. 学生成绩Group命令
151-
```
151+
{% highlight javascript %}
152152
db.students.group({
153153
key:{age:1},
154154
cond: {age:{$exists:true}},
155155
reduce:function(cur, result) { result.count += 1; result.total_gpa += cur.gpa; result.ava_gpa = result.total_gpa / result.count;},
156156
initial: { count: 0 , total_gpa: 0}
157157
})
158-
```
158+
{% endhighlight %}
159159
11. 数据聚合 -- 流水线
160+
161+
{% highlight javascript %}
160162
各年龄段平均GPA计算和排序
161163

162-
```
164+
163165
db.students.aggregate([
164166
{$match:{age:{$exists:true}}},
165167
{$group:{_id:"$age", count: {$sum:1}, total_gpa:{$sum:"$gpa"}}},
@@ -188,10 +190,10 @@ db.students.aggregate(
188190
{$sort: {cc:-1}}
189191
]
190192
)
191-
```
193+
{% endhighlight %}
192194

193195
12 数据聚合MapReduce
194-
```
196+
{% highlight javascript %}
195197
按age分组计算平均gpa (错误)
196198
db.students.mapReduce(
197199
function(){
@@ -278,4 +280,4 @@ db.students.aggregate([
278280

279281
])
280282

281-
```
283+
{% endhighlight %}

_scss/_highlights.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ code {
108108
/* Name.Namespace */
109109
.highlight .nn { color: #93A1A1 }
110110
/* Name.Other */
111-
.highlight .nx { color: #555 }
111+
.highlight .nx { color: #aaa }
112112
/* Name.Property */
113113
.highlight .py { color: #93A1A1 }
114114
/* Name.Tag */

0 commit comments

Comments
 (0)