Larvel MongoDB (add, delete, modify)
PHP MongoDB driver Chinese document
PHP MongoDB driver official documentation
Some details are not written completely, if you want to learn please read the official documentation!
Add, delete, change, and query are the same as mysql driver operations
Add $rs = DB: : collection ('Set name')->insertGetId($param);
$rs = DB::collection('Set name')->insert($param); Delete $rs = the DB: : collection ('Set name')->where(["_id"= >1])->delete(); Change $rs = DB: : collection ('Set name')->where(["_id"= >1])->update(['name'= <'Lost Goodness']); Check $result = the DB: : collection ('Set name')->where(["_id"= >1])->get();
// Paging function
$results = DB::collection('Set name')->paginate(10);
// This can also do pagination and sortingorderBy()    Sorting function, skip()      Skip a few limits ()    $rs = DB::collection('Set name')->orderBy('age'.'asc')->skip(10))->limit(10)->get();
Copy the code
Add, delete, or modify an embedded array
Directing the operator
increase// Insert array $addToSet if it already exists
$rs = DB::collection('user_files_folder')->update(['$addToSet'= > ['child'= > ['name'= >'Two Fools']])
// Insert array $push when insert if already exist the same still insert
$rs = DB::collection('user_files_folder')->update(['$push'= > ['child'= > ['name'= >'Two Fools'$rs = DB::collection($rs = DB::collection('user_files_folder')->update(['$pull'= > ['child'= > ['name'= >'Two Fools']])// Note that the WHERE condition can be used if multiple structures are required. The connection$set is the modify operator, corresponding to the modify object (array) modify object can also be used if multiple structures are required. Join, where the $symbol represents the corresponding key (because the data structure here is an array, $represents the corresponding sequence number, can also be written to die09 -DB::collection('stock')->where(['info.id'= >"118b110212"])->update([
$set'= > ['info.$.id'=>"118b110jkjkjk" ] ]);Copy the code