zoukankan      html  css  js  c++  java
  • 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)})

  • 相关阅读:
    光盘和U盘
    解决时间同步
    僵尸进程 和 孤儿进程
    Centos虚拟机设置网络模式
    常用CDN 和 后台管理模板
    微信小程序wxs如何使用
    kubernetes/client-go--使用 Clientset 获取 Kubernetes 资源对象
    samplecontroller
    volcano
    DNS欺骗
  • 原文地址:https://www.cnblogs.com/frisk/p/9463137.html
Copyright © 2011-2022 走看看