Db.collectionname.find (<CRITERIA>, <projection>)
<criteria> filter criteria for document documents of optional type
<projection> Optional Type document matches the result field {field 1:<booleadn>, field 2:<boolean> ...} (That is, the second parameter controls the display of the result field under filter conditions)
When we don't provide any parameters, we're querying the entire document.
The following example matches the result field
In the above example we first selected a document with ID 2, and in the result we only want to display the Bigname
Curious, you're going to do this.
Can the display ID not show bigname this field? Duangduangduang the error means that you cannot combine the inclusion and non-inclusion of the fields (excluding the _id that MongoDB provides _id can be implemented with and without merging) on the example
That is, when we only want a column, we can use the above way when more than a few classes of the parameter is 1 or we just want a column does not display when the parameter to set a column is 0
And after Db.collectionname.find () can also add some methods of querying cursors, such as limit () limits the number of result sets skip () skips a certain entry, returns the result set sort ()
First I inserted many IDs in the database with different data to test the above several cursor methods
The value of the cursor property above using sort () is 1 when the ascending attribute value is-1 is descending
Use of OR
$lt |
< |
$lte |
<= |
$gt |
> |
$gte |
>= |
$in |
Inch |
$nin |
Not in |
$ne |
!= |
Referring to a few operators above, we do a few find operations
Match NULL This is the document value that the query does not exist for the field
Like query
Note that the bottom two are through the like query, only the pre-match or post-match cases will not be matched to the transfer
The above example is a post-match like
Add a collection operation here Db.collectionname.count () query the number of documents in the dataset
where query
Db.collectionname.count (<query>) Number of entries matching query
Db.collectionname.remove (<query>,justone) justone only one document is deleted when the Boolean value is True
First, when we want to delete all the documents in a collection, Db.collection.remove ({}) must provide an empty object for the purpose of deleting all the objects.
When we do not provide a second argument, the default is false to remove all matching query items from the document
MongoDB Array Query
The structure of the document is a way to store arrays. How do we implement an array of queries?
If the value you provide after the key value is an array, when you supply the value in the array of value of the stored key, MongoDB is returning the result we need.
Above we found that a document record value value is not an array that is the method of MongoDB's find () can match the value of the array and can match a single value above the example is to match all the name of the value contains an array of a document or the name value is a document
Match a specific array (in fact this is nothing more than just listing to be against the below)
When we want to match the value of a part of an array, that is, a part of the value of the array.
Match according to the length of the elements of the array
Add a value to an array
$push This operation can only be used on a document item where value is an array, create an array item using the value if the key does not exist
The argument that follows the $PUSHALL push is the value to add to the array if it is an array then add an array to the array $pushAll is to add multiple values to the array at the same time each item is added to the array at a time
(differentiate between them two is one and multiple differences)
$pop Delete the first array item when the value after the last array entry is 1 when the value is 1
$pull remove a specific value from the array
$pullAll remove multiple values from an array
In the example above, there are two identical values that can be seen to be deleted.
MongoDB Basic Instruction Learning (2)