MongoDB學習筆記(一)

來源:互聯網
上載者:User

標籤:

前言:MongoDB內建一個javascript shell用戶端,因此支援javascript文法及大部分函數。 

MongoDB常用基礎資料型別 (Elementary Data Type)介紹:

  1. null:空值或者不存在的欄位
  2. Boolean:true,false
  3. 數值型:MongoDB中數值型預設為Double,可以使用NumberInt()函數及NumberLong()函數分別指定某個欄位為整型和長整型。
  4. 字串:
  5. 日期:new Date().getTime();//擷取目前時間的時間戳記
  6. 數組:var uArray=[ "張三","李四","王五"];

MongoDB基本操作

增加資料:   

  單體插入: 

var p1 ={    "name":"張傑",    "age":NumberInt("28") ,//MongoDB中數實值型別預設為Double    "sex":false}db.user.insert(p1);
View Code

  批量插入:

    1. 直接插入一個數組:

var p2=[    {        "name":"張傑",        "age":NumberInt("28") ,//MongoDB中數實值型別預設為Double        "sex":false    },    {        "name":"李娜",        "age":NumberInt("33") ,//MongoDB中數實值型別預設為Double        "sex":true    },    {        "name":"唐嫣",        "age":NumberInt("28") ,//MongoDB中數實值型別預設為Double        "sex":true    }]db.user.insert(p2);
View Code

    2. 迴圈插入

var p2=[    {        "name":"李晨",        "age":NumberInt("28") ,//MongoDB中數實值型別預設為Double        "sex":false    },    {        "name":"鄧超",        "age":NumberInt("33") ,//MongoDB中數實值型別預設為Double        "sex":false    },    {        "name":"鄭凱",        "age":NumberInt("28") ,//MongoDB中數實值型別預設為Double        "sex":false    }]for(var i=0;i<p2.length;i++){    db.user.insert(p2[i]);}
View Code

刪除資料

    刪除user集合中的所有文檔:

db.user.remove();//刪除user集合中的所有文檔
View Code

    刪除指定集合:

var where={    "name":"鄭凱"};db.user.remove(where);//刪除user集合中所有"name"為"鄭凱"的文檔
View Code

    直接刪除集合   

db.user.drop();//刪除user集合
View Code

 

MongoDB學習筆記(一)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.