91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

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

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

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

瑞丽市| 巫山县| 阜宁县| 津市市| 宕昌县| 来凤县| 中阳县| 四川省| 西藏| 五大连池市| 澄城县| 芜湖县| 阿克陶县| 额济纳旗| 东源县| 龙川县| 苍溪县| 平利县| 元谋县| 通渭县| 六枝特区| 鄯善县| 揭东县| 左贡县| 十堰市| 胶南市| 桦甸市| 莆田市| 阿尔山市| 花莲市| 吉首市| 湘潭县| 河西区| 普格县| 梅河口市| 临潭县| 康平县| 东平县| 鄢陵县| 杨浦区| 九龙县|