Mongodb what is a collection




















MongoDB provides various query operators to specify the criteria. For a list of the query operators, see Query Selectors. Combine comparison operators to specify ranges for a field. The following operation returns from the bios collection documents where birth is between new Date '' and new Date '' exclusive :. The following operation returns all the documents from the bios collection where birth field is greater than new Date '' and death field does not exists:. The following examples query the name embedded field in the bios collection.

The name field must match the embedded document exactly. The query does not match documents with the following name fields:. The following operation returns documents in the bios collection where the embedded document name contains a field first with the value "Yukihiro" and a field last with the value "Matsumoto". The query uses dot notation to access fields in an embedded document:.

The query matches the document where the name field contains an embedded document with the field first with the value "Yukihiro" and a field last with the value "Matsumoto". For instance, the query would match documents with name fields that held either of the following values:. The following examples query the contribs array in the bios collection.

The following operation returns documents in the bios collection where the array field contribs contains the element "UNIX" :. The following operation returns documents in the bios collection where the array field contribs contains the element "ALGOL" or "Lisp" :. For a list of array specific query operators, see Array. The following examples query the awards array in the bios collection.

The following operation returns documents in the bios collection where the awards array contains an element with award field equals "Turing Award" :. The following operation returns documents in the bios collection where the awards array contains at least one element with both the award field equals "Turing Award" and the year field greater than The projection parameter specifies which fields to return.

The following operation queries the bios collection and returns all fields except the first field in the name embedded document and the birth field:. The following operation finds documents in the bios collection and returns only the name field and the contribs field:.

The following operation queries the bios collection and returns the last field in the name embedded document and the first two elements in the contribs array:. With the use of aggregation expressions and syntax, you can project new fields or project existing fields with new values.

For example, the following operation uses aggregation expressions to override the value of the name and awards fields as well as to include new fields reportDate , reportBy , and reportNumber. To set the reportRun field to the value 1 The operation returns the following documents:. Project Fields to Return from Query. The find method returns a cursor to the results. In mongosh , if the returned cursor is not assigned to a variable using the var keyword, the cursor is automatically iterated to access up to the first 20 documents that match the query.

You can set the DBQuery. To manually iterate over the results, assign the returned cursor to a variable with the var keyword, as shown in the following sections. The following example uses the variable myCursor to iterate over the cursor and print the matching documents:. The following example uses the cursor method next to access the documents:.

To print, you can also use the printjson method instead of print tojson :. The mode affects the behavior of explain and determines the amount of information to return.

The possible modes are:. For backwards compatibility with earlier versions of cursor. For more information on the modes, see Verbosity Modes. The behavior of db. For write operations, db. Starting in MongoDB 4. Instead, you can either:. To see the list of operations supported by db. To see the list of query modifiers supported by db.

You can chain multiple modifiers to db. For an example, see Explain find with Modifiers. A collection is a grouping of MongoDB documents. Documents within a collection can have different fields. A collection is the equivalent of a table in a relational database system. A collection exists within a single database. The Collections screen lists the existing collections and views in the selected database.

Each list item includes the name and other general information for the collection or view. To access the Collections screen for a database, from the Databases screen either:. The Collections screen displays the following information for each collection in the selected database:.

Compass bases the document count that appears on the Collections screen on cached metadata using collStats. This count might differ from the actual document count in the collection. For example, an unexpected shutdown can throw off the count.



0コメント

  • 1000 / 1000