0

I have a MongoDB database, where each object has a structure as follows:

{
    "_id" : ObjectId("593b1bb421426f7245ef473e"),
    "brand" : "Ford",
    "model" : "Sierra",
    "specific" : [ 
        "Start", 
        "Car", 
        "Ford", 
        "Sierra "
    ]
}

Using Mongoose and Nodejs, I'd like make a query to find the objects where the second position of the array (index 1) matches with the "Car" value (inside the array placed in the "specific" key of the object).

My query at the moment is:

Car.find({specific: {1: 'Car'}}, function (err, vehicle) {
    if (err) {
      return err;
    } else {
      console.log(vehicle);
    }
});

On the console is printing: [ ]

Any idea of how the query should be?

Community
  • 1
  • 1
Rafa
  • 115
  • 1
  • 8
  • Hi Adam, thanks for your answer. I tried that before, perhaps it works on the mongo console. But from inside an application using mongoose is not accepting the dot notation. Car.find({breadcrumb.1: 'Car'}, function (err, vehicle){.........} "SyntaxError: Unexpected number" – Rafa Jun 13 '17 at 18:43
  • The problem was tha I wasn't using the quotes Car.find({"specific.1": 'Car'} Thanks for putting me on the right tack!! – Rafa Jun 13 '17 at 18:50

0 Answers0