0

I have a Mongoose Schema like this:

var userSchema = new mongoose.Schema({

   name: String,
   email: String,
   data: [String],
});

And using Mongoose search I want to compare some value with the first element of data, im trying something like:

users.FindOne({data[0]: value}, {}, function(err, resp){
  //code
});

That of course doesen't work, how can I compare a value with the n element of an array?.

Thanks in advance.

1

1 Answer 1

1

You can use numeric indexes in your keys, but you need to use dot notation:

users.FindOne({'data.0': value}, {}, function(err, resp){
  //code
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.