mongoodb(增刪改查)crud

2021-10-08 02:16:02 字數 1305 閱讀 3794

一.查詢

1.查詢使用者集合中所有文件 [陣列文件]

user.find().then(result=> console.log(result))

2.通過_id欄位查詢文件

user.find().then(result=>console.log(result))

3.findone方法返回一條文件,預設返回集合第一條文件

user.findone().then(result=>console.log(result))

4.查詢使用者集合中年齡字段大於x或者小於x的文件 匹配大於小於

user.find(' at position 6: lt:50}̲}).then(result=…in :[『足球』]}})

6.旋轉要查詢的字段 選擇要查詢的字段

user.find().select(『name eamil -_id』).then(result=>console.log(result))

7.將資料按照年齡大小進行公升序排序

user.find(.sort(『age』)).then(result=>console.log(result))

8.根據年齡字段進行降序排列

user.find(.sort(』-age』)).then(result=>console.log(result))

9.skip()跳過前倆條資料 limit限制查詢2條數量

user.find().skip(2).limit(2).then(result=>console.log(result))

二. 2.0刪除乙個

user.findoneanddelete().then(result=>console.log(result))

2.1刪除多個

user.deletemany().then(result=>console.log(result))

user.deletemany({}).then(result=>console.log(result))

三. 更新文件 3.1更新單個

user.updateone(,).then(result=>console.log(result))

user.updateone(,).then(result=>console.log(result))

3.2更新多個 查詢條件為空所有的年齡都修改為56歲

user.updetemany({},).then(result=>console.log(result))

四.集合關聯查詢

post.find().populate(『author』).then(result=>console.log(result))

mysql增刪改查效果 mysql增刪改查

檢視所有資料庫 mysql show databases 建立乙個庫ghd並指定字符集為utp8 mysql create database ghd charset utf8 檢視mysql支援的字符集 mysql show char set 建立乙個表,並設定id為主鍵 create table ...

mysql增刪改查擴充套件 MySQL增刪改查

1 插入 insert 1 insert into 表名 values 值1 值2 例子 insert into t1 values zengsf 23 fengshao 22 2 insert into 表名 欄位1,values 值1 例子 insert into t1 name values ...

增刪改查 JS陣列增刪改查這點事兒

1 length屬性 length屬性是陣列最重要的屬性,沒有之一,length屬性告訴我們這個陣列內有多少個資料元素,當length 0時說明陣列時乙個空陣列。我們想要遍歷陣列時可以直接將遍歷的終點設為 length 1。這是本文的重點,我們從增刪改查方面入手,梳理方法的作用和用法,有利於記憶和使...