• MongoDB操作


    判断是否存在:
    db.course.find({"filename": { $exists: true } }).count()
    移除字段:
    db.course.update({},{$unset:{"filename":""}},{multi:true})
    db.test.update({},{$unset:{"file_path":""}},{multi:true})

    批量增加字段:
    db.course.update({},{$set:{"filename":"mongo"}},{multi:true})
    db.test.update({},{$set:{"UpdateMark":"true"}},{multi:true})

    查询字段值相同的数量:
    db.test.find({"$where": "this.fields1 == this.fields2"}).count()

    重命名键:

    db.test.update({}, {$rename : {"name" : "NAME"}}, false, true)

    导出json:

    mongoexport  -u root -p "admin123" -d test_db -c test -o xxxxxxx.json --authenticationDatabase "admin"

    -u:用户名

    -p:密码

    -d:目标数据库

    -c:数据库collections(表名)

    -o:导出文件名

    --authenticationDatabase:选填


    导入json:

    mongoimport  -u root -p "admin123" -d test_db -c test --file xxxxxxx.json --authenticationDatabase "admin"

    --file:导入文件

    pymongo的部分操作:

    from bson import ObjectId
    import pymongo
    conn = pymongo.MongoClient('mongodb://root:123456@127.0.0.1/admin')
    db = conn.test_db
    str = "5sdfadsfasdfxzcasdfasdfas"
    findinfo = db.Report.find({"_id" : ObjectId(str)})

  • 相关阅读:
    2015 省赛随便写写
    有向图强连通分量
    复杂状态的动态规划
    hdu 3350
    树状DP
    十字链表矩阵
    最优矩阵链乘
    poj 3778
    Poj 3771 hdu 3405
    [2015hdu多校联赛补题]hdu5302 Connect the Graph
  • 原文地址:https://www.cnblogs.com/frisk/p/9463137.html
Copyright © 2020-2023  润新知