"SequoiaDB Giant Sequoia Database" find() Overview 4

Example

Query all records without specifying the cond and sel fields.

db.sample.employee.find()

Query the records matching the conditions, that is, set the content of the cond parameter. The following operation returns the records in the collection employee whose age field value is greater than 25 and the name field value is "Tom".

db.sample.employee.find( { age: { $gt: 25 }, name: "Tom" } )

Specify the returned field name, that is, set the content of the sel parameter. If there are records {age: 25, type: "system"} and {age: 20, name: "Tom", type: "normal" }, the following operations return the age and name fields of the records.

db.sample.employee.find( null, { age: "", name: "" } )
    {
        "age": 25,
        "name": ""
    }
    {
        "age": 20,
        "name": "Tom"
    }

Use the index ageIndex to traverse the records of the age field in the collection employee and return.

db.sample.test.find( {age: {$exists:1} } ).hint( { "": "ageIndex" } )
{
        "_id": {
        "$oid": "5812feb6c842af52b6000007"
        },
        "age": 10
}
{
        "_id": {
        "$oid": "5812feb6c842af52b6000008"
        },
        "age": 20
}

Select the records whose age field value is greater than 10 in the set employee (for example, use the  $gt  query), and return from the fifth record, that is, skip the previous four records.

db.sample.employee.find( { age: { $gt: 10 } } ).skip(3).limit(5)

If the number of records in the result set is not greater than 3, then no records are returned; if the number of records in the result set is greater than 3, starting from the fourth, at most 5 records are returned.

 

Return the records in the collection employee whose age field value is greater than 20 (for example, use the  $gt  query), set to return only the name and age fields of the records, and sort them in ascending order of the age field value.

db.sample.employee.find( { age: { $gt: 20 } }, { age: "", name: "" } ).sort( { age: 1 } )

Click on Jushan Database Documentation Center for more information

Guess you like

Origin blog.csdn.net/weixin_45890253/article/details/112936727