mongodb-php

Mongodb query specific month|year not date

﹥>﹥吖頭↗ 提交于 2019-11-26 11:26:34
问题 How can I query a specific month in mongodb, not date range, I need month to make a list of customer birthday for current month. In SQL will be something like that: SELECT * FROM customer WHERE MONTH(bday)=\'09\' Now I need to translate that in mongodb. Note: My dates are already saved in MongoDate type, I used this thinking that will be easy to work before but now I can\'t find easily how to do this simple thing. 回答1: You can do that using aggregate with the $month projection operator: db

Calculate skip value for given record for sorted paging

送分小仙女□ 提交于 2019-11-26 08:34:30
问题 I\'m trying to calculate the skip value for a given record in a mongo db collection using the php driver. So taking a given record, find out the index of that record within the entire collection. Is this possible? Currently I\'m selecting all records and manually doing an index of on the array of results. 回答1: This is called "forward paging" which is a concept you can use to "efficiently page" through results in a "forward" direction when using "sorted" results. JavaScript logic included

Mongodb $push in nested array

不问归期 提交于 2019-11-25 22:47:37
问题 I want add new data my nested array My document is: { \"username\": \"erkin\", \"email\": \"erkin-07@hotmail.com\", \"password\": \"b\", \"playlists\": [ { \"_id\": 58, \"name\": \"asdsa\", \"date\": \"09-01-15\", \"musics\": [ { \"name\": \"INNA - Cola Song (feat. J Balvin)\", \"duration\": \"3.00\" }, { \"name\": \"blabla\", \"duration\": \"3.00\" } ] } ] } I want add music in this playlist section: { \"username\": \"erkin\", \"email\": \"erkin-07@hotmail.com\", \"password\": \"b\", \