zoukankan      html  css  js  c++  java
  • mongodb operate update and delete

    update name as a to newA,but update one record

    db.movies.update({name:'a'},{$set:{name:'newA'}})
    

    update all

    db.movies.update({name:'a'},{$set:{name:'newA'}},{multi:true})
    

    when save() has _id paramter ,as same as update,otherwise,as insert()

    db.movies.save({_id:Object("56461345adsa564"),name:'newA'})
    

    delete all

    db.movies.remove({name:'newB'})
    

    delete one

    db.movies.remove({name:'newB'},1)
    

    remove all records

    db.movies.remove()
    

    restrive specify filed what you want ,1 for yes ,0 for no, default _id is alway exist,can set _id:0

    db.movies.find({},{name:1});
    

    restrive two records,if limit method no paramter,will serach all records

    db.movies.find().limit(2)
    

    skip

    db.movies.find().limit(2).skip(1)
    

    order by filed 1 for Ascending, -1 for descend

    db.movies.find().sort({name:-1})
    

    aggregate

    db.movies.aggregate([{$group:{'_id':'$name',num:{$sum:1}}}]) find fileld what you want sum or avge and so more
    
    the result is like:
    [{_id:'newA',sum:5},
    {_id:'newB',sum:1}]
    

    thanks ,that is all foundation ,haha.

  • 相关阅读:
    [转]mysql视图学习总结
    [转]mysql索引详解
    mysql索引的操作
    [转]mysql的约束
    mysql表的操作
    【转】mysql的数据类型
    java泛型
    java 8新特性
    Dubbo有意思的特性介绍
    dubbo + zookeeper
  • 原文地址:https://www.cnblogs.com/cyany/p/9956101.html
Copyright © 2011-2022 走看看