I am new in Meteor, and especially in MongoDB.
I have googled a lot regarding this issue but nothing found related to this.
So there is an app that contains two collections: EventsCollection
and RacesCollection
and runs on Meteor server.
The RacesCollection
has number of records like:
RacesCollection.insert({raceId:"r1", eventId:"e1", raceName:"Moto race 1", status:"statusDetail", mode:"modeDetail"});
RacesCollection.insert({raceId:"r2", eventId:"e1", raceName:"Moto race 2", status:"statusDetail", mode:"modeDetail"});
This is the resultant collection which contains rows having eventId = e1
var race = RacesCollection.find({eventId: "e1"});
Now what i want to do is to simply access the fields of race
into javascript, something like race.raceId
, race.raceName
. How to implement this? Is there any getter method for accessing particular data field?
And how to iterate through multiple rows of race
in case it contains number of rows?
Any recommendation will be appriciated.
Display all documents from a collection with the help of find () method − Following is the query to access the array in a MongoDB collection and fetch a specific document −
A database stores one or more collections of documents. In MongoDB, databases hold one or more collections of documents. To select a database to use, in mongosh, issue the use <db> statement, as in the following example: If a database does not exist, MongoDB creates the database when you first store data for that database.
MongoDB stores data records as documents (specifically BSON documents) which are gathered together in collections. A database stores one or more collections of documents. In MongoDB, databases hold one or more collections of documents. To select a database to use, in mongosh, issue the use <db> statement, as in the following example:
The dbstats method gets statistics of a database. The example connects to the testdb database and shows its statistics. This is a sample output. The find function creates a cursor for a query that can be used to iterate over results from MongoDB. In the example, we retrieve all docs from cars collection.
use ForEach :
db.databaseName.find(
{
field:"valueofField"
}
).forEach(function(obj){
print(obj.fieldname)
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With