zoukankan      html  css  js  c++  java
  • mongoDB数据库基础

    mongoDB数据库

    查看数据库:show dbs;

    创建/切换数据库:use f28(f28为数据库名)

    查看正在运行的数据库:db;

    CRUD增删改查(create retrive update delate)

    增:insert

    db.users.insert({username:"jack",password;123456})
    

    删:remove

    dropDatabase();删除当前数据库

    db.users.remove({username:"aaaaaa"})//只删除这一条数据

    db.users.remove();集合users下全部数据都删除了

    改:update

    db.users.update({username:"bbbbbb",{$set:{password:222222}}})//只修改username为bbbbbb里的password
    db.users.update({username:"aaaaaa"},{password:111111})//这条数据将被password替换掉
    db.users.update({},{$set:{password:22222}},{multi:true});3.0新版本修改所有password
    db.users.update({},{$set:{password:22222}},false,true);3.0一下旧版本修改所有password
    

    差:find

    db.users.find().pretty();//查看所有被整理后的数据(即被美化)
    db.users.find({username:"aaaaaa"})//精确匹配
    db.users.find({age:{$gt:20}});//匹配年龄大于20的
    db.users.find({age:{$gt:20,$lt:30}})//匹配年龄大于20的,且小于30的
    db.users.find({age:{$gt:20},gender:"male"});//匹配年龄大于20的,且是男的
    db.users.find({$or:[age:{$gt:20},{gender:"male"}]});//匹配年龄大于20的,或则为男的
    db.students.find({name:{$regex:"^a",$option:"$i"}});//模糊查询,以a开头不论大小写
    db.students.find(0.limit(5).skip(1)//跳过第一条数据开始显示,总共显示5条数据
    db。students.find().sort({age:1})//按年龄从小到大排序,1代表升序,-1代表降序
    
    $lt:<
    $gt:>
    $gte:<=
    $lte:>=
    $ne:!=
  • 相关阅读:
    [Leetcode 56] 55 Jump Game
    [Leetcode 57] 61 Rotate List
    [Leetcode 61] 73 Set Matrix Zeros
    [Leetcode 62] 74 Search a 2D Matrix
    [Leetcode 64] 78 Subsets
    [Leetcode 63] 77 Combinations
    [Leetcode 58] 63 Unique Path II
    python学习笔记第1章节 基础知识
    python学习笔记第2章节 分支,循环,还有条件
    visual studio 2008 试用版评估期已结束的解决方法(转载)
  • 原文地址:https://www.cnblogs.com/rwalker/p/5618625.html
Copyright © 2011-2022 走看看