• 关于集合的size的操作


    1.创建集合:

    创建指定大小的集合:(大小为5)

    db.createCollection('colle1',{capped:true,size:5})

    2.插入五条数据:

    > db.colle1.insert({name:'qlq',age:25})
    WriteResult({ "nInserted" : 1 })
    > db.colle1.insert({name:'qlq1',age:25})
    WriteResult({ "nInserted" : 1 })
    > db.colle1.insert({name:'qlq12',age:25})
    WriteResult({ "nInserted" : 1 })
    > db.colle1.insert({name:'qlq13',age:25})
    WriteResult({ "nInserted" : 1 })
    > db.colle1.insert({name:'qlq14',age:25})
    WriteResult({ "nInserted" : 1 })
    > db.colle1.find()
    { "_id" : ObjectId("5ab482055114c7b7fd6e83d8"), "name" : "qlq", "age" : 25 }
    { "_id" : ObjectId("5ab482095114c7b7fd6e83d9"), "name" : "qlq1", "age" : 25 }
    { "_id" : ObjectId("5ab4820d5114c7b7fd6e83da"), "name" : "qlq12", "age" : 25 }
    { "_id" : ObjectId("5ab482105114c7b7fd6e83db"), "name" : "qlq13", "age" : 25 }
    { "_id" : ObjectId("5ab482135114c7b7fd6e83dc"), "name" : "qlq14", "age" : 25 }

    3.再插入一条数据并测试:

    > db.colle1.insert({name:'qlq15',age:25})
    WriteResult({ "nInserted" : 1 })
    > db.colle1.find()
    { "_id" : ObjectId("5ab482095114c7b7fd6e83d9"), "name" : "qlq1", "age" : 25 }
    { "_id" : ObjectId("5ab4820d5114c7b7fd6e83da"), "name" : "qlq12", "age" : 25 }
    { "_id" : ObjectId("5ab482105114c7b7fd6e83db"), "name" : "qlq13", "age" : 25 }
    { "_id" : ObjectId("5ab482135114c7b7fd6e83dc"), "name" : "qlq14", "age" : 25 }
    { "_id" : ObjectId("5ab482475114c7b7fd6e83dd"), "name" : "qlq15", "age" : 25 }

     总结: 发现指定size的集合当超过指定大小时是将最早进来的覆盖掉,也就是删除掉最早进来的然后重新添加最新的。

  • 相关阅读:
    !!!C#——进制转换!
    冒泡排序后用二分查找法查找位置
    简陋的4位验证码程序(范围内取随机数)
    这个年龄计算程序相当不科学,体验还是差差哒
    8.7课堂随笔
    字符串中查询关键字
    !汉企的WiFi网速好快
    重度强迫症患者的九九乘法表
    自选数字和范围的整除算法
    day52
  • 原文地址:https://www.cnblogs.com/qlqwjy/p/8629658.html
Copyright © 2020-2023  润新知