mongodb

作者: 次序 | 来源:发表于2018-11-17 12:21 被阅读0次
    登录数据库
    use admin
    db.auth("myUserAdmin", "abc123" )
    
    
    #security:
      #authorization: enabled
    
    
    
    
    C:\Program Files\MongoDB\Server\4.0\data\
    C:\Program Files\MongoDB\Server\4.0\log\
    
    
    use admin
    db.createUser(
      {
        user: "zhangcunli",
        pwd: "haliluya100",
        roles: [
           { role: "userAdminAnyDatabase", db: "admin" }
        ]
      }
    )
    readWrite
    
    dev dev100
    test test100
    
    
    
    批量插入
    db.getCollection('mc').insert([{x:1.3},{x:1.5}])
    
    分页、倒序
    db.getCollection('customer').find({"_id" :{$gt:ObjectId("5ac2e43074702d3bd0cfd9ab")}}).sort({"_id":-1}).limit(3)
    分页
    public List<Customer> findById() {
    Query query = new Query();
    query.addCriteria(Criteria.where("_id").gt(new ObjectId("5ac2e43074702d3bd0cfd9ab")));
    // query.with(new Sort(Sort.Direction.DESC,"_id"));
    Long pageSize = mongoTemplate.count(query, Customer.class);
    log.info("-------pageSize------"+pageSize);
    return mongoTemplate.find(query.limit(2), Customer.class); 
     
    }
    
    

    相关文章

      网友评论

          本文标题:mongodb

          本文链接:https://www.haomeiwen.com/subject/phbbfqtx.html