Git Product home page Git Product logo

mongodb's Introduction

mongodb class

composer require liwenzhi/mongodb

##查询一条

$config = [
    'hostname' => '127.0.0.1',
    'port'     => 27017,
    'database' => 'dbname',
    'username' => '',
    'password' => '',
];
$mongo = Mongodb::getInstance($config);
//方式1
$mongo->collection('tablename')->where(['_id'=>'xxx'])->find();
//方式2
$mongo->collection('tablename')->find('xxx');

##查询多条

$mongo = Mongodb::getInstance($config);
$mongo->collection('tablename')->where(['city'=>'xxx'])->sort(['age'=>1])->skip(0)->limit(10)->select();

##添加一条

$doc = [
	'name'=>'liwz',
	'age'=>12
];
$mongo = Mongodb::getInstance($config);
$mongo->collection('tablename')->insert($doc);

##添加多条

$docs =[
	 [
		'name'=>'wangsan',
		'age'=>18
	], 
	[
		'name'=>'liwz',
		'age'=>12
	]
];
$mongo = Mongodb::getInstance($config);
$mongo->collection('tablename')->insertMulti($docs);

##删除数据

$mongo = Mongodb::getInstance($config);
$mongo->collection('tablename')->where(['age'=>12])->delete();

##修改数据

$mongo = Mongodb::getInstance($config);
$mongo->collection('tablename')->where(['_id'=>12])->update(['coin'=>9999]);

##其他函数

$mongo->max()//最大值
$mongo->min()//最小值
$mongo->inc()//累加/减操作
$mongo->count()//统计count
$mongo->distinct()//去重
  
  
  //条件函数
  
$mongo->where()//普通where条件
$mongo->whereIn()
$mongo->whereInAll()
$mongo->whereOr()
$mongo->whereNotIn()
$mongo->whereGt()
$mongo->whereLt()
$mongo->whereLte()
$mongo->whereGte()
$mongo->whereBetween()
$mongo->whereNotEqual()
$mongo->group()

mongodb's People

Contributors

liwz avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.