Doubt with mongodb test

Asked

Viewed 351 times

1

I am a beginner in Mongo I have a question with select/query.

I need to make a query that searches at the base Yoda and in the collection configuracoes return all documents that hold the key tipoRecibo with a value equal to gps.

I know I have to wear

$filter
= array

however of Collection Forward caught me, if someone give me a super help, thank you.

2 answers

3


You can use the method find() to run a query that fetches documents from a Mongodb collection. All queries in Mongodb have as their scope a single collection.

Queries can return all documents from a collection, or only documents that match a particular filter or criteria.
You can specify the filter or criterion in a document and send it as parameter to the method find().

The method find() returns results of a cursor, an iterable object that emits documents.

In the Mongo shell connected with an instance mongod, switch to the bank yoda:

use yoda

To get all documents from the collection, you can call the method find() without a criteria document. For example, the following operation fetches all documents in the collection configuracoes:

db.configuracoes.find()

The result set contains all documents in the collection configuracoes.

To define equal conditions, simply associate the field with the value:

{<campo>: <valor>}

In your case, you can do so:

db.configuracoes.find({"tipoRecibo": "gps"})

1

Browser other questions tagged

You are not signed in. Login or sign up in order to post.