Hello @Alexander_Laub, welcome to the MongoDB Community forum!
Here is some info and hope is useful to you.
Do I need to download or locally store a document to be able to search it? Or to read it?
When you perform a read operation on a collection, you get some/one/none documents from the database into your application. The number of documents returned depend upon the filter you specify in the find
method. Then there is a feature called as projection. Projection allows you specify in the find
method what specific fields of the document you want to retreive from the database for the matching filter. The search happens on the database server and the application receives the result.
The find
method retreives a cursor into the application, which can be used to read the documents. The cursor will be empty, if there is no match for the specified filter.
Consider multiple documents in a collection in the following format:
{ _id: 1, name: "John", city: "New York", country: "US" }
{ _id: 2, name: "Jane", city: "New York", country: "US" }
{ _id: 3, name: "Raj", city: "Delhi", country: "India" }
The query:
db.collection.find( { city: "New York" }, { name: 1, city: 1, _id: 0 } )
In the above query:
{ city: "New York" }
is the query filter.
{ name: 1, city: 1, _id: 0 }
is the projection.
The query returns a cursor with two matching documents. The output document structure will be like this with two fields:
{ name: "John", city: "New York" }
Do I need to define an own bson document in order to fill it with the data extracted or can I just extract integers or characters?
The returned documents are to be loaded into some kind of structure / records (I am not familiar with C language terminology) within your application, and use it further.
Reference:
EDIT ADD:
MongoDB data is stored as BSON types. In general, when you store a number in the database it is by default a double (other numeric data types are int, long and float, and there is a NumberDecimal
type mainly used for precise decimal numbers like currency). You can check the data type of a field using the $type
operator on a specific field. There is mapping from the BSON to the programming language types as part of the driver functionality. Each programming language has their own mappings.