mongoDB 根據條件來查詢文件

2021-10-07 17:09:54 字數 696 閱讀 7152

//插入資料庫模組

const mongoose = require('mongoose');

//連線資料庫

mongoose.connect('mongodb://localhost/playground', )

.then(result => ).then(result => )

//查詢大於15,小於50的文件

//  user.find( }).then(result => ) 

//查詢包含足球的文件

// user.find( }).then(result => )

//選擇要查詢的字段,如果不需要查詢_id,在前面加個-

//  user.find().select('name email').then(result => );

//根據年齡字段進行公升序排列

// user.find().sort('age').then(result => console.log(result));

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

// user.find().sort('-age').then(result => console.log(result));

//skip跳過多少條資料 limit限制查詢數量

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

mongodb中根據內嵌文件中的條件查詢

在寫報使用者訂單報表的時候遇到了乙個mongodb的查詢問題,上網上也找了下資料,在這裡記錄一下 根據訂單文件中的內嵌文件裡的資料進行查詢資料庫 prodcatid 02001 txntype 30 prodid zdsjyz0622 03 ordertime 2017 06 23 17 50 20...

Mongodb 插入 條件查詢

插入準備資料,mongodb一大特點就是 no schema。無模式的檔案式儲存。用關係型資料庫的說法就是可以儲存任意欄位而不需要事先建立該欄位 簡單的插入方式 db.userinfo.insert db.userinfo.insert 以上格式的資料可以直接插入mongodb資料庫 通過 db.u...

mongodb條件查詢(二)

db.c1.find 1 文件數 即記錄數 db.c1.count 8 db.c1.find count 8 2 返回的前多少條記錄,如下返回前兩條記錄 db.c1.find limit 2 3 返回記錄的起點,如下跳過前6條記錄,從第7條開始 db.c1.find skip 6 4 排序,如下1為...