zoukankan      html  css  js  c++  java
  • mongodb crud

    //添加数据
    db.users.insert({"uName":"张三","age":30,"gender":""});
    db.users.insert({"name":"李四","wifes":[{"wname":"小崔"},{"wname":"小李"}]});
    
    //查询数据
    db.students.find();
    //查询数据(带格式显示)
    db.users.find().pretty();
    
    //分页查询
    db.books.insert({"bookName":"mybatis入门","price":19.9});
    db.books.insert({"bookName":"spring","price":199.9});
    db.books.insert({"bookName":"springmvc","price":69.9});
    db.books.insert({"bookName":"mysql","price":39.9});
    db.books.insert({"bookName":"python","price":59.9});
    
    // skip(起始页码,从0开始) limit(每页显示数量)
    db.books.find().skip(0).limit(2);
    db.books.find().skip(4).limit(2);
    
    //条件查询
    //select * from books where price = 19.9
    db.books.find({"price":19.9});
    
    // price = ? and bookName = ?
    db.books.find({"price":19.9,"bookName":"mybatis入门"});
    
    //or  
    db.books.find({$or:[{"bookName":"mybatis入门"},{"bookName":"spring"},{"price":59.9}]});
    
    // <
    db.books.find({"price":{$lt:69.9}})
    
    // <=
    db.books.find({"price":{$lte:69.9}});
    
    // >
    db.books.find({"price":{$gt:69.9}});
    
    // >=
    db.books.find({"price":{$gte:69.9}});
    
    // !=
    db.books.find({"price":{$ne:69.9}});
    
    // >=39.9 and <=69.9
    db.books.find({"price":{$gte:39.9,$lte:69.9}});
    
    //修改
    //udpate book set price = ? where bookName = ?
    db.books.update({"bookName":"mybatis入门"},{$set:{"price":119.99}});
    //若根据修改条件 需要修改多条数据时,需要添加参数 multi:true
    db.books.update({"bookName":"mybatis入门"},{$set:{"price":1.99}},{multi:true});
    
    //删除
    //delete book where bookName = ?
    db.books.remove({"bookName":"spring"});
  • 相关阅读:
    no,no,不要使用kill -9
    Linux中etc目录详解
    Quartz任务调度器的使用
    RMI(Remote Method invocation,远程方法访问)
    SilverLight扩展控件RadTreeView
    SiverLight和HTML交互
    SilverLight控件之ContextMenu和RadContextMenu(菜单)
    SilverLight之向后台请求数据-WebClient
    SilverLight控件样式及控件模版
    在SilverLight中代码编写可选择树节点
  • 原文地址:https://www.cnblogs.com/yuefeng123/p/9617444.html
Copyright © 2011-2022 走看看