MongoDB query advanced operation (3)

MongoDB query advanced operation (3)

1. Basic query, query data according to id


2. Query data that is not equal to a certain value: {field:{$ne:value}} Check the documents whose value of the filed column is not equal to value. For example, query data whose cat_id is not equal to 3.


3. Query data greater than a given value, $gt For example: query documents with id greater than 13, and only display the goods_name column


4. Query data less than a given value, $lt For example: query documents whose id is less than 5, and only display the goods_name column


5. Query data less than or equal to a given value, $lte For example: query documents whose id is less than or equal to 5, and only display the goods_name column


6. Query two data with id 5 and 15. $in


7. Query data with id between 5 and 13 $and


8. Query data whose id is not 3 and whose id is not 13. Use $and respectively ($nin is equivalent to not in) (the values ​​given by $nor are not queried) to achieve




9. mod: True if a remainder condition is satisfied. For example: query to retrieve the data that matches, and judge that the value of the id value is modulo operation and the result is 0.


10. exists: Query a given column, if it exists, query it. For example, to query documents with sex attribute columns.


11, all: The given conditions must be satisfied before querying.


12. sort: sort, sort according to the given field, 1 means ascending order, -1 means descending order


13. limit(): Returns the number of results. skip(): Returns the number of skipped results. For example, the data returned by the query is displayed from the 6th id, and a total of 5 pieces of data are displayed.


14. count(): Count the number of returned results. When adding skip() and limit(), to get the actual number of results returned, a parameter true is required, otherwise the total number of results that meet the query conditions is returned. .


Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326898133&siteId=291194637