\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{cgeeeeh} \pdfinfo{ /Title (mongodb.pdf) /Creator (Cheatography) /Author (cgeeeeh) /Subject (MongoDB Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{MongoDB Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{cgeeeeh} via \textcolor{DarkBackground}{\uline{cheatography.com/191000/cs/40129/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}cgeeeeh \\ \uline{cheatography.com/cgeeeeh} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 30th September, 2023.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{增+查}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{use shop 使用collections} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{db.products.insert()/insertOne()/insertMany({[}data{]},\{ordered:false\}),注意\_id不能重复,且insertmany报错不会回滚已经插入的数据} \tn % Row Count 4 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{ordered:false,意味着啥}} \tn % Row Count 5 (+ 1) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{db.products.insertOne(\{"name":"Ben's book", price:12.99\})} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.authors.insertMany\{ {[}\{name: "Ben", age:22\}, \{name: "Ben", age:22\}{]} \}} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{db.products.find(\{"name":"Ben"\}, \{\_id:0, "age":1\}),要筛选啥,要的列扣1,\_id是自带的索引} \tn % Row Count 12 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.products.find(\{age: \{\$gt:30\}\}),还有\$eq,\$ne,\$gt,\$gte,\$lt,\$lte,\$eq可以接null} \tn % Row Count 14 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{db.products.find(\{\$expr:\{\$gt:{[}"\$volume","\$target"{]}\}\}),volumn和target两个字段,比大小,必须用\$expr} \tn % Row Count 17 (+ 3) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.movies.find(\{"rating.average":\{\$gt:7\}\}),embedded需要用.和双引号} \tn % Row Count 19 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{\#embeded+多重:db.users}.find(\{hobbies:\{title:'sports',frequency:4\}\})} \tn % Row Count 21 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.movies.find(\{genre: {[}"Drama"{]}\}),genre有且仅有Drama,如果没有方括号就是包括Drama} \tn % Row Count 23 (+ 2) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{\#就要这两个值,且有序:db}.boxoffice.find(\{"genre": {[}'drama','action'{]} \})} \tn % Row Count 25 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#好几个值都要,可以再有多余的,且无序:db.boxoffice.find(\{"genre":\{\$all:{[}'drama','action'{]}\}\})} \tn % Row Count 28 (+ 3) % Row 13 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{\#找到第一条,db.movies.findOne()}} \tn % Row Count 29 (+ 1) % Row 14 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{find函数in符号:\{\$in,\$nin:{[}30{]}/{[}30,40{]}\}相当于sql的in not in} \tn % Row Count 31 (+ 2) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{增+查 (cont)}} \tn % Row 15 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{find函数or/and/not:db}.movies.find(\{\$or: {[} \{"rating.average":\{\$lt:5\}\}, \{"rating.average":\{\$gt:9.3\}\} {]}\})} \tn % Row Count 3 (+ 3) % Row 16 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{find函数,\$and函数会把doc里面所有的doc都遍历一遍,可能一个doc满足条件A,一个满足B,就能被选入}} \tn % Row Count 6 (+ 3) % Row 17 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{find函数,\$elemMatch \seqsplit{是doc同时满足才能入选}} \tn % Row Count 8 (+ 2) % Row 18 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{find函数exists:\$exists:} true} \tn % Row Count 9 (+ 1) % Row 19 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{find函数判断类型:\{\$type: "string"/"double"/"number"\}} \tn % Row Count 11 (+ 2) % Row 20 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{find函数,summary:"musical"可以找到所有summary里面包含musical的document}} \tn % Row Count 13 (+ 2) % Row 21 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{find函数,summary:\{\$regrex: /musical/\}可以找到所有包含summary里面包含musical的document} \tn % Row Count 16 (+ 3) % Row 22 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{\#doc里的hobbies里面有两个子doc} db.users.find(\{'hobbies':\{\$size:2\}\})} \tn % Row Count 18 (+ 2) % Row 23 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{在find写完后.count()可以统计数量}} \tn % Row Count 19 (+ 1) % Row 24 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{去重:db.students.distinct("class"}, \{ grade: "A" \})} \tn % Row Count 21 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{区别,优势}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{MongoDB允许存储的数据部分,甚至完全不同,而sql有固定的列}} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{Mongo一对一的关系(比如病人对一张病例单)用embeded存储,而sql会存在不同的表里}} \tn % Row Count 5 (+ 3) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{Mongo一对一的关系(一个名字既有薪水也有车辆信息),如果两个表都单独做分析,就单独存储。如果都要分析,那也可以join}} \tn % Row Count 9 (+ 4) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{Mongo一对多的关系:数据里有别的collection的document的id}} \tn % Row Count 11 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{Mongodb多对多:一个document里面存储多个\_id}} \tn % Row Count 13 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{db.books.aggregate({[} \{\$lookup:\{from: "authors", localField:"authors", foreignField:"\_id", as: "creators"\} \} {]})} \tn % Row Count 16 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{把authorjoin进book里面:from是外表,localfield是本表的列,foreignfield是外表的列,as是本表新引进来数据的名字}} \tn % Row Count 19 (+ 3) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{改}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.customers.update( \{\}, \{\$set: \{orders: {[}{]}\} \} )} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{CRUD \seqsplit{运算都是原子计算,不会回滚}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{insertOne()} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{删}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.patients.deleteMany(\{"history.disease":"flu"\})} \tn % Row Count 1 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{聚合函数}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.students.aggregate({[}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\$group: \{\_id: "\$class", // 使用 \$group \seqsplit{按班级分组,distinctGrades:} \{ \$addToSet: "\$grade" \} // 使用 \$addToSet \seqsplit{获取每个班级的不同年级} \} \},} \tn % Row Count 5 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\$project: \{\_id: 0, // 不显示默认的 \_id 字段,class: "\$\_id", // \seqsplit{重新命名字段,distinctGrades:} 1 // 保留 distinctGrades 字段\} \}} \tn % Row Count 8 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{{]})} \tn % Row Count 9 (+ 1) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{sort/projections/slices}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#降序db.movies.find(\{\}).sort(\{ 'rating.average':-1,runtime:1 \})/1是升序} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{\#跳过和限制打印:find()}.sort().skip(2).limit(5)} \tn % Row Count 4 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\#投影 find(),\{url:1,name:1,\_id:0\} \seqsplit{id是强制显示的,除非你取消}} \tn % Row Count 6 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\#slice db.movtes.find(\{"rating.average":{[}\$gt;9{]}\},\{genres:\{\$slice:{[}1,2{]}\}, \seqsplit{name:1),genre是一个数组,取第二第三个element,再取name}} \tn % Row Count 9 (+ 3) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{数据格式转化:\$convert:} \{ input: \textless{}string\textgreater{}, to: "date"\} converts a string to ISODate} \tn % Row Count 11 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\$isoWeekYear extracts the year value of a date field} \tn % Row Count 13 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{update}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{\#先用find函数查,再用updateOne}, updateMany去修改} \tn % Row Count 2 (+ 2) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{db.users.updateOne(\{name: " Cammy Soh"\}, \{\$set: {[}hobbies: {[}\{title: "cooking", frequency: 7\}{]}\}\}) 把cammy的hobbies \seqsplit{属性给删除,改成这个新值}} \tn % Row Count 6 (+ 4) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.users.updateOne(\{name:"Cammy Soh"\}, \{\$set:{[}age:20,phoneNo: 97332212{]}\} )} \tn % Row Count 8 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{db.users.updateMany({[}"hobbies .title":"sports"\}, \$set:fisSport:true{]}\})} \tn % Row Count 10 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.users.updateOne(\{name:"Jayden Choi"\}, \{\$inc:\{age: 1\}\})} \tn % Row Count 12 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{报错,因为不能同时修改两个值:db}.user.updateOne(\{ name:"BAA" \}, \{\$inc:\{age:1\}, \$set:\{age:10\} \})} \tn % Row Count 15 (+ 3) % Row 6 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.users.updateOne(\{ name:"abc" \}, \{\$min/\$max/\$mul: \{age:15\}\})} \tn % Row Count 17 (+ 2) % Row 7 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{db.users.updateMany(\{isSport: true\}, \{\$unset: \{phone: " "\}\} )} \tn % Row Count 19 (+ 2) % Row 8 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.users.updateMany(\{ \}, \{\$rename: \{age: "totalage"\}\} )} \tn % Row Count 21 (+ 2) % Row 9 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{updateMany还有一个\{upsert=true\}函数,默认为false} \tn % Row Count 23 (+ 2) % Row 10 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.users.updateMany(\{ hobbies:\{\$eleMatch: \{"frequency":\{\$gte:5\}, title:"sports"\}\}\}, \{\$set:\{"hobbies.\$": \{title:"sports", frequency:15\}\}\})} \tn % Row Count 26 (+ 3) % Row 11 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\$是指对那些满足筛选条件的第一个document更改值,\${[}{]}是对所有的更改值} \tn % Row Count 28 (+ 2) % Row 12 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.users.updateMany(\{"hobbies.frequency":\{\$gt:3\}\},\{\$set:\{"hobbies.\$.goodFrequency":True\}\})新建立一个列} \tn % Row Count 31 (+ 3) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{update (cont)}} \tn % Row 13 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.users.updateMany(\{\},\{\$set:\{"hobbies.\${[}el{]}.goodFrequency":true\}\}, \{arrayFilters:{[}\{"el.frequency":\{\$gt:3\}\}{]}\})} \tn % Row Count 3 (+ 3) % Row 14 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\seqsplit{最后一个参数告诉我们,第一个参数筛选的结果中,也不是所有的都需要改}} \tn % Row Count 5 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{group}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{db.users.aggregate({[}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\$match:\{gender:"female"\}\},} \tn % Row Count 2 (+ 1) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\$group: \{\_id: \{isoWeekYear: \{ \$isoWeekYear: "\$date" \},incidentType: "\$incidentType"\}, totalAge:\{\$sum: "\$dob.age"\}\}\}} \tn % Row Count 5 (+ 3) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{\$sort: \{totalPersons:-1\}\}。1是asc,-1desc,可以用之前groupby里面选中的列} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\$project: \{\_id:0, gender:1, fullName:\{\$concat:{[}"hello,world"{]}{]}\}\}\}} \tn % Row Count 9 (+ 2) % Row 5 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\{addfields:\}首先,层层递进地加列,不要一次性计算很多,第二,如果要计算到之前加进去的列,需要新建一个addfields来算} \tn % Row Count 13 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{字符串函数}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\{\$toUpper,"\$name.first"\},\{\$toLower:"\$name.last"\}} \tn % Row Count 1 (+ 1) % Row 1 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\$substrCP:{[}"\$name.first", 0 ,1{]} extracts starting from the 0 (1st) char for 1 char -\textgreater{} "B"} \tn % Row Count 3 (+ 2) % Row 2 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\$substrCP:{[}"\$name.first", 0 ,2{]} extracts starting from the 0 (1st) char for 2 char -\textgreater{} "Be"} \tn % Row Count 5 (+ 2) % Row 3 \SetRowColor{white} \mymulticolumn{1}{x{5.377cm}}{\$subtract:{[}int1,int2{]} perform subtraction int1 – int2} \tn % Row Count 7 (+ 2) % Row 4 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{\$strLenCP: \textless{}string\textgreater{} returns the length (number of char) of a string} \tn % Row Count 9 (+ 2) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{\seqsplit{projection中的array操作}}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}