二、Mongodb实战之——Mongodb Shell实现简单插入和查询
来源:互联网 发布:袁岚峰 知乎 编辑:程序博客网 时间:2024/06/05 19:43
- insert
向集合中插入文档
source code
function (obj, _allow_dot) { if (!obj) { throw "no object passed to insert!"; } if (!_allow_dot) { this._validateForStorage(obj); } if (typeof obj._id == "undefined" && !Array.isArray(obj)) { var tmp = obj; obj = {_id:new ObjectId}; for (var key in tmp) { obj[key] = tmp[key]; } } this._db._initExtraInfo(); this._mongo.insert(this._fullName, obj); this._lastID = obj._id; this._db._getExtraInfo("Inserted");}
example:
>db.users.insert({"userName":"chjzh","pwd":"123"})
- find
在集合中查询符合条件的文档,find()返回集合中所有文档
source code
function (query, fields, limit, skip, batchSize, options) { return new DBQuery(this._mongo, this._db, this, this._fullName, this._massageObject(query), fields, limit, skip, batchSize, options || this.getQueryOptions());}
example
>db.users.find({"userName":"chjzh"})
- save
向集合中插入文档,与insert不同的是,若集合中存在重复的id则insert不做插入,而save则更改原来的内容为新内容
source code
function (obj) { if (obj == null || typeof obj == "undefined") { throw "can't save a null"; } if (typeof obj == "number" || typeof obj == "string") { throw "can't save a number or string"; } if (typeof obj._id == "undefined") { obj._id = new ObjectId; return this.insert(obj); } else { return this.update({_id:obj._id}, obj, true); }}
example
>db.users.save({"userName":"chjzh","pwd":"111111"})
- count
统计集合中满足条件的文档个数
source code
function (x) { return this.find(x).count();}
example
>db.users.count()
- 二、Mongodb实战之——Mongodb Shell实现简单插入和查询
- 三、Mongodb实战之——Mongodb Shell实现简单更新
- mongodb简单的数据插入和查询
- mongodb实战之查询
- MongoDB学习二--MongoDB 数据结构和查询
- 一、Mongodb实战之——Ubuntu安装Mongodb
- mongodb shell 插入
- MongoDB shell插入数据
- MongoDB入门6——查询(二)
- MongoDB分片实战(三):性能和优化 插入、查询和更新
- MongoDB的数据插入和查询
- MongoDB 文档的查询和插入操作
- Mongodb 插入 条件查询
- MongoDB实战系列之二:MongoDB的常用操作
- MongoDB实战系列之二:MongoDB的常用操作
- MongoDB实战系列之二:MongoDB的常用操作
- mongoDB 之 查询和新增
- 【mongodb系统学习之十】mongodb查询(二)
- 关于类型转换的一件小事
- 第一次上机实验报告
- stl中map用法详解
- JAVA语言学习_02(关于static)
- Servlet详解
- 二、Mongodb实战之——Mongodb Shell实现简单插入和查询
- FreeType2中文手册
- 第二次上机报告
- java图片处理:缩放、剪切
- 跟我一起学建站目录
- myeclipse集成JBoss7.1
- 【转】POJ 1159 Palindrome【经典的DP回文问题】
- 转 注解@
- 51单片机控制zigbee模块实现的多机通讯系统