Question

I am trying to use the find method to return documents that meet multiple criteria like so:

db.issues.find({ 'title.name': name, 'title.year': year, 'title.publisher': publisher }, function(err, issues) { ...

I get an empty array back as a result.

If I try the same query directly in the mongodb console, I get the results back as expected.

In mongojs, I am able to retrieve results if I only supply one attribute, like so:

db.issues.find({ 'title.name': name }, function(err, issues) { ...

So, how do I perform a search using multiple attributes? Do I need to use a different method?

UPDATED 2/2/2014 7:56 The issue schema is as follows:

{
    title: { name: 'Some title name', year: 1999, publisher: 'Some publisher' },
    number: "122", 
    variant: null,
    print: "1",
    year: "1999",
    certification: { type: "Some certification", grade: 10 },
    url: "http://www.someurl.com",
    sales: []
}
Was it helpful?

Solution

There is no difference in how mongojs handles queries as it's intention is to mimic ( somewhat ) the behavior of the mongo shell.

Are you sure your criteria actually returns something? As it stands you possibly have an issue there. If you still cannot diagnose this, post up the result you expect to get and some of your schema as an edit. Don't forget to check your var's that numbers aren't strings and vice versa.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top