首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

02-JavaScript Shell

database,一个 database 中有多个 collection。

collections,类似 MySQL 中的 table。

同一个 database 中的所有 collections,会写入硬盘上的同一个文件。

插入操作

> use tutorial

switched to db tutorial

查询操作

> db.users.find({

... _id: ObjectId("5a7bfb5ac53b13638b843c78"),

... username: "waterdragon",

... })

{ "_id" : ObjectId("5a7bfb5ac53b13638b843c78"), "username" : "waterdragon" }

等价于

> db.users.find({ $and: [

... { _id: ObjectId("5a7bfb5ac53b13638b843c78") },

... { username: "waterdragon" }

... ] })

{ "_id" : ObjectId("5a7bfb5ac53b13638b843c78"), "username" : "waterdragon" }

更新操作

删除操作

索引和explain()

返回了 4 条记录(nReturned),搜索了 20000 条记录(totalDocsExamined)。

一个索引都没用上(totalKeysExamined)。

Basic Administration

> show databases

local 0.000GB

tutorial 0.001GB

> use tutorial

> show collections

numbers

> db.stats()

{

"db" : "tutorial",

"collections" : 1,

"objects" : 20000,

"avgObjSize" : 35,

"dataSize" : 700000,

"storageSize" : 352256,

"numExtents" : 0,

"indexes" : 2,

"indexSize" : 389120,

"ok" : 1

}

...

看函数的代码实现

function (obj, opts) {

if (obj == null)

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, opts);

}

else {

return this.update(, obj, Object.merge(, opts));

}

}

  • 发表于:
  • 原文链接https://kuaibao.qq.com/s/20180603G0DSZI00?refer=cp_1026
  • 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号(企鹅号)传播渠道之一,根据《腾讯内容开放平台服务协议》转载发布内容。
  • 如有侵权,请联系 cloudcommunity@tencent.com 删除。

扫码

添加站长 进交流群

领取专属 10元无门槛券

私享最新 技术干货

扫码加入开发者社群
领券