In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Php7+mongodb class is what kind of, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can gain something.
Recommend a php7+ mongodb trigonal class
Due to the needs of the project, the project was upgraded to php7. But after the upgrade, I found that the mongo extension was no longer available. Only mongodb extensions are supported above php7.0. The driver of the mongodb extension is more complex and verbose than the monmgo extension. I've been looking for it online for a long time. Finally found a relatively concise mongodb class. The grammar is similar to that of mongo. Clear, natural.
Project address https://github.com/mongodb/mongo-php-library
Because the project is contributed by foreign friends. So there is no clear document to read. Here are some common methods.
Get instance $uri = "mongodb://username:password@host/database"; $client = new\ MongoDB\ Client ($uri); get collection $collection = $client- > selectCollection ('test','test'); get a piece of data $data = $collection- > findOne ([' id'= > 1]); get multiple pieces of data $where = ['type'= > 1] $options = array ('projection' = > array (' id' = > 1, 'age' = > 1,' name' = >-1), / / specify which fields to return 1 means return-1 means that no 'sort' = > array (' id' = >-1) is returned, / / specify sorting field 'limit' = > 10, / / specify the number of returned entries' skip' = > 0, / / specify the starting position) $data = $collection- > find ($where,$options)-> toArray (); var_dump ($data); deweighting $fileName = 'name';$where = [' id' = > ['$lt' = > 100]] $ret = $this- > collection- > distinct ($fileName,$where); insert a piece of data $data = array ('id' = > 2,' age' = > 20, 'name' = >' Zhang San'); $ret = $collection- > insertOne ($data); $id=$ret- > getInsertedId () Bulk insert $data = array (['id' = > 1,' age' = > 21, 'name' = >' 1xiaoli'], ['id' = > 2,' age' = > 22, 'name' = >' 2xiaoli'], ['id' = > 3,' age' = > 23, 'name' = >' 3xiaoli'], ['id' = > 4,' age' = > 26, 'name' = >' 4xiaoli'], ['id' = > 5,' age' = > 24] 'name' = >' 5xiaoli'], ['id' = > 6,' age' = > 25, 'name' = >' 6xiaoli'],) $ret = $collection- > insertMany ($data); # return insert idvar_dump ($ret- > getInsertedIds ()); update a $ret = $collection- > updateOne (array ('id' = > 2), array (' $set' = > array ('age' = > 56)); update multiple $ret = $collection- > updateMany (array (' id' = > ['$gt' = > 1]), array ('$set' = > array ('age' = > 56,' name' = > x') Delete one $ret = $collection- > deleteOne (array ('id' = > 2)); delete multiple $collection- > deleteMany (array (' id' = > array ('$in' = > array (1,2) Aggregate $ops = [['$match' = > ['type'= > [' $in'= > [2p4], ['$sort' = > ['list.create_time' = >-1] / / sort order cannot be changed, otherwise it will cause sorting confusion. Please note that sorting is followed by paging], [' $skip' = > 0], ['$limit' = > 20000],] $data = $collection- > aggregate ($ops); foreach ($data as $document) {var_dump ($document);} is it helpful for you to read the above? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.