亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

mongoBD學習(三)插入與查詢數據

發布時間:2020-06-17 12:39:37 來源:網絡 閱讀:389 作者:adelazhu 欄目:MongoDB數據庫

root@adela-vm:/opt/mongodb_simple# numactl --interleave=all bin/mongod -f conf/mongod.conf
about to fork child process, waiting until server is ready for connections.
forked process: 4904
child process started successfully, parent exiting

root@adela-vm:/opt/mongodb_simple# ./bin/mongo 127.0.0.1:12345
MongoDB shell version: 2.6.9
connecting to: 127.0.0.1:12345/test

> show dbs    //顯示有幾個數據庫
admin  (empty)
local  0.078GB

> use adela   //切換到adela數據庫,不需要事先定義
switched to db adela

> show dbs      //adela數據庫沒有增加內容,所以不現實
admin  (empty)
local  0.078GB
>

RDBMS中的表 對應 mongoDB中的集合collections ,插入內容為json格式
db.集合名(表).insert(json格式)
db.adela_collection.insert({"x":1})

顯示所有的集合
> show collections   
adela_collection
system.indexes

插入數據
> db.adela_collection.insert({y:2})
WriteResult({ "nInserted" : 1 })
> db.adela_collection.find()
{ "_id" : ObjectId("5514f09641daf13c28f7bdb7"), "x" : 1 }
{ "_id" : ObjectId("5514f12b41daf13c28f7bdb8"), "y" : 2 }
 
_id是系統自動分配的,也可以自定義,但是 _id 不能重復
> db.adela_collection.insert({a:1,_id:1})
WriteResult({ "nInserted" : 1 })
> db.adela_collection.insert({a:2,_id:1})
WriteResult({
        "nInserted" : 0,
        "writeError" : {
                "code" : 11000,
                "errmsg" : "insertDocument :: caused by :: 11000 E11000 duplicate key error index: adela.adela_collection.$_id_  dup key: { : 1.0 }"
        }
})

查詢adela_collection全表
> db.adela_collection.find()  //不加參數

查詢x為1的數據
> db.adela_collection.find({x:1})
{ "_id" : ObjectId("5514f09641daf13c28f7bdb7"), "x" : 1 }
{ "_id" : ObjectId("5514f1d241daf13c28f7bdb9"), "x" : 1 }

循環插入一批數據
> for(i=1;i<11;i++)db.adela_collection.insert({z:i})
WriteResult({ "nInserted" : 1 })

> db.adela_collection.find()
{ "_id" : ObjectId("5514f09641daf13c28f7bdb7"), "x" : 1 }
{ "_id" : ObjectId("5514f12b41daf13c28f7bdb8"), "y" : 2 }
{ "_id" : ObjectId("5514f1d241daf13c28f7bdb9"), "x" : 1 }
{ "_id" : 1, "a" : 1 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe54"), "z" : 1 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe55"), "z" : 2 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe56"), "z" : 3 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe57"), "z" : 4 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe58"), "z" : 5 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe59"), "z" : 6 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5a"), "z" : 7 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5b"), "z" : 8 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5c"), "z" : 9 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5d"), "z" : 10 }

計數count
> db.adela_collection.find().count()
14

skip跳過多少條數據
limit限制返回多少條數據
sort使用排序

> db.adela_collection.find()
{ "_id" : ObjectId("5514f09641daf13c28f7bdb7"), "x" : 1 }
{ "_id" : ObjectId("5514f12b41daf13c28f7bdb8"), "y" : 2 }
{ "_id" : ObjectId("5514f1d241daf13c28f7bdb9"), "x" : 1 }
{ "_id" : 1, "a" : 1 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe54"), "z" : 1 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe55"), "z" : 2 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe56"), "z" : 3 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe57"), "z" : 4 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe58"), "z" : 5 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe59"), "z" : 6 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5a"), "z" : 7 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5b"), "z" : 8 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5c"), "z" : 9 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5d"), "z" : 10 }

> db.adela_collection.find().skip(4)
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe54"), "z" : 1 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe55"), "z" : 2 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe56"), "z" : 3 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe57"), "z" : 4 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe58"), "z" : 5 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe59"), "z" : 6 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5a"), "z" : 7 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5b"), "z" : 8 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5c"), "z" : 9 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe5d"), "z" : 10 }

> db.adela_collection.find().skip(4).limit(5)
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe54"), "z" : 1 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe55"), "z" : 2 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe56"), "z" : 3 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe57"), "z" : 4 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe58"), "z" : 5 }

> db.adela_collection.find().skip(4).limit(5).sort({z:1})
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe54"), "z" : 1 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe55"), "z" : 2 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe56"), "z" : 3 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe57"), "z" : 4 }
{ "_id" : ObjectId("5514f5eca1b17c0bb936fe58"), "z" : 5 }

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

长乐市| 沂水县| 喀喇沁旗| 石家庄市| 安平县| 苏尼特左旗| 朝阳县| 桦甸市| 巴彦淖尔市| 秦皇岛市| 同仁县| 沙田区| 陇川县| 利川市| 沂水县| 迭部县| 桃源县| 杭锦后旗| 玉树县| 象山县| 屏山县| 新巴尔虎左旗| 博白县| 刚察县| 木兰县| 黄梅县| 县级市| 当阳市| 清镇市| 肃宁县| 成安县| 蚌埠市| 盱眙县| 娄烦县| 贵南县| 格尔木市| 大英县| 香格里拉县| 中超| 岳阳市| 图片|