MongoDB基础知识 02

6 数据类型

6.1 null : 表示空值或者不存在的字段

{"x":null}

6.2 布尔型 : 布尔类型只有两个值true和false

{"x" : true}

6.3 数值  :默认使用64位浮点型数值

对于整数值,可使用NumberInt类或者NumberLong类,

{"x":3.14}
{"x":3} {"x",:NumberInt("3")}
{"x",:NumberLong("3")}

6.4 字符串:UTF-8字符串都可表示为字符串类型的数据。

6.5 日期:被存储为自新纪元以来经过的毫秒数,不存储时区。Date()返回的是字符串(日期的字符串表示), new Date()返回的是日期的对象。

6.6 正则表达式:查询时,使用正则表达式作为 限定条件,语法也和javascript的正则表达式语法相同。

6.7 数组 : 数据列表或者数据集可表示为数组。

6.8 内嵌文档:文档可以嵌套其他文档。

6.9 对象id :对象id是一个12字节的ID,是文档的唯一标识。

6.10 二进制数据 :任意字节的字符串。

6.11 代码 : 查询和文档中可以包括任意JavaScript代码。

7 使用MongoDB shell

7.1 对于MongoDBt特有的功能,可以使用help命令查看:

> help
db.help() help on db methods
db.mycoll.help() help on collection methods
sh.help() sharding helpers
rs.help() replica set helpers
help admin administrative help
help connect connecting to a db help
help keys key shortcuts
help misc misc things to know
help mr mapreduce show dbs show database names
show collections show collections in current database
show users show users in current database
show profile show most recent system.profile entries with time >= 1ms
show logs show the accessible logger names
show log [name] prints out the last segment of log in memory, 'global' is default
use <db_name> set current database
db.foo.find() list objects in collection foo
db.foo.find( { a : 1 } ) list objects in foo where a == 1
it result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x set default number of items to display on shell
exit quit the mongo shell

可以直接在shell中输入函数名,看到相应函数的实现代码:

> db
zhangxindb
> show collections
blog
system.indexes
> db.blog.update
function ( query , obj , upsert , multi ){
assert( query , "need a query" );
assert( obj , "need an object" ); var wc = undefined;
// can pass options via object for improved readability
if ( typeof(upsert) === 'object' ) {
assert( multi === undefined,
"Fourth argument must be empty when specifying upsert and multi with an object." ); var opts = upsert;
multi = opts.multi;
wc = opts.writeConcern;
upsert = opts.upsert;
} var result = undefined;
var startTime = (typeof(_verboseShell) === 'undefined' ||
!_verboseShell) ? 0 : new Date().getTime(); if (!wc)
wc = this.getWriteConcern(); if ( this.getMongo().writeMode() != "legacy" ) {
var bulk = this.initializeOrderedBulkOp();
var updateOp = bulk.find(query); if (upsert) {
updateOp = updateOp.upsert();
} if (multi) {
updateOp.update(obj);
}
else {
updateOp.updateOne(obj);
} try {
result = bulk.execute(wc).toSingleResult();
}
catch( ex ) {
if ( ex instanceof BulkWriteError || ex instanceof WriteCommandError ) {
result = ex.toSingleResult();
}
else {
// Other exceptions thrown
throw ex;
}
}
}
else {
this._validateUpdateDoc(obj);
this.getMongo().update(this._fullName, query, obj,
upsert ? true : false, multi ? true : false ); // enforce write concern, if required
if (wc)
result = this.runCommand("getLastError", wc instanceof WriteConcern ? wc.toJSON() : wc);
} this._printExtraInfo("Updated", startTime);
return result;
}
>

7.2 使用shell执行脚本 

除了以交互方式使用shell,还可以直接传递脚本给shell。

例如:mongo script1.js script2.js script3.js

也可以使用load()函数,从交互式shell中运行脚本。

例如:load("script1.js")

MongoDB基础知识 02的更多相关文章

  1. MongoDB基础知识 01

    MongoDB基础知识  1. 文档  文档是MongoDB中的数据的基本单元,类似于关系型数据库管理系统的行. 文档是键值对的一个有序集.通常包含一个或者多个键值对. 例如: {”greeting& ...

  2. DataBase MongoDB基础知识记录

    MongoDB基础知识记录 一.概念: 讲mongdb就必须提一下nosql,因为mongdb是nosql的代表作: NoSQL(Not Only SQL ),意即“不仅仅是SQL” ,指的是非关系型 ...

  3. Mongodb 笔记01 MongoDB 简介、MongoDB基础知识、启动和停止MongoDB

    MongoDB 简介 1. 易于使用:没有固定的模式,根据需要添加和删除字段更加容易 2. 易于扩展:MongoDB的设计采用横向扩展.面向文档的数据模型使它能很容易的再多台服务器之间进行分割.自动处 ...

  4. MongoDB基础知识记录

    MongoDB基础知识记录 一.概念: 讲mongdb就必须提一下nosql,因为mongdb是nosql的代表作: NoSQL(Not Only SQL ),意即“不仅仅是SQL” ,指的是非关系型 ...

  5. 常见问题:MongoDB基础知识

    常见问题:MongoDB基础知识 ·MongoDB支持哪些平台? ·MongoDB作为托管服务提供吗? ·集合(collection)与表(table)有何不同? ·如何创建数据库(database) ...

  6. day03-MySQL基础知识02

    MySQL基础知识02 4.CRUD 数据库CRUD语句:增(create).删(delete).改(update).查(Retrieve) Insert 语句 (添加数据) Update 语句(更新 ...

  7. MongoDB 基础知识

    一. 基础知识 1. MongoDB是一个文档型的数据库,文档就是一个键值对的有序集合. 例如这样:{"greeting":"hello world"} 2. ...

  8. MongoDB基础知识(二)

    一.基本概念 1:文档(document)是MongoDB中数据的基本单元,非常类似于关系型数据库管理系统中的行 2:集合(collection)可以看做是一个拥有动态模式(dynamic schem ...

  9. MongoDB基础知识

    一.Mongodb简介 Mongodb是基于分布式文件存储的数据库,用C++编写: Mongodb是nosql(not-only-sql)数据库: Mongodb '无状态模式',不用去设计,直接用, ...

随机推荐

  1. JavaScript中的作用域和闭包

    首先强烈安利<你不知道的JavaScript>,JS初学者进阶必读. 对于从C++.Java等静态语言转向JavaScript的初学者(比如我)来说,JS一些与众不同而又十分要紧的特性使得 ...

  2. JSONP技术原理及实现

    跨域问题一直是前端中常见的问题,每当说到跨域,第一浮现的技术必然就是JSONP JSONP在我的理解,它并不是ajax,它是在文档中插入一个script标签,创建_callback方法,通过服务器配合 ...

  3. libConfuse的使用

    前言 在软件编程中经常会使用到一些参数,在存储方面一般有使用XML的,也有使用文本文件的,或者使用数据库的等.我们软件平台一些参数是使用XML文件存储,在读取方面的速度还可以,但在写回文件速度一般.也 ...

  4. Less小记

    Less除了在引用的时候link和script有顺序之外,在编译过程中,less中的代码顺序也会造成对样式的重置.

  5. In Place Upgrade of CentOS 6 to CentOS 7

    Note: This is not the most highly recommended method to move from CentOS 6 to CentOS 7 ... but it ca ...

  6. 正则表达式替换img标签src值!!!

    方法一: 相关链接:http://bbs.csdn.net/topics/320185735 实例:此实例自己做的时候讲字符串加了alt进行了有关修改  不清楚看上面链接 string test = ...

  7. 学习Swift -- 协议(下)

    协议(下) 在拓展中添加协议成员 通过扩展使得Dice类型遵循了一个新的协议,这和Dice类型在定义的时候声明为遵循TextRepresentable协议的效果相同.在扩展的时候,协议名称写在类型名之 ...

  8. 暂时告别Solr了

    好久没更新博客了,是因为最近一直忙于找工作,以及生活的一些琐碎事情. 新的工作虽然薪水不高,但是全新的项目还是让我蛮兴奋的. 现在从事的是数据工程师,又重新接触了Hadoop,Hive,Sqoop这些 ...

  9. 去除UINavigationBar默认透明度的方法

    UINavigationbar的属性translucent,用来控制导航条的透明度的: iOS7+版本后,navigationbar的translucent属性默认为YES,及默认带有透明度 [sel ...

  10. 使用SeaJS实现模块化JavaScript开发

    前言 SeaJS是一个遵循CommonJS规范的JavaScript模块加载框架,可以实现JavaScript的模块化开发及加载机制.与jQuery等JavaScript框架不同,SeaJS不会扩展封 ...