Reputation: 121
I am trying a select a value from the Mongo DB just like we do in SQL In SQL we query like :
SELECT column-name FROM table-name WHERE column-name = " something "
In the same way I am trying to do the following in Meteor to access the Mongo DB
collection.find({}, {Col-name1: {Col-name2 : 'xyz'}})
here I am trying to pull an integer value of Col-name1
that corresponds to Col-name2
: xyz
This leads to [object Object]
that is a string in the html page. This should rather be a integer value. What am I doing wrong?
Thanks!
Upvotes: 0
Views: 59
Reputation:
You want,
collection.find({Col-name2 : 'xyz'}, {Col-name1: 1})
{Col-name2 : 'xyz'}
is the criteria to match and {Col-name1: 1}
is to return only Col-name1
field in the document and the document by default will also have _id
. If you dont want _id
, you have to specify it like {Col-name1: 1, _id: 0}
Also mongodb, doesn't return the field value. It always return as document/s. So, you have to access the field yourself in your code. For example, to access Col-name1
from a returned document, you have to use
document['Col-name1']
in your code.
Upvotes: 1