0

Query

 Blog.find({date: 'December 27, 2014'}, function (err, data) {

        console.log("Data: " + data);
        console.log("Value: " + data.coverFilename);
 }

Dump

Data: { _id: 549de8f6afa8b87c2139559d,
  tags: 'tag1, tag2, tag3 hallo',
  permaLink: 'testtitle',
  coverFilename: '3b6f0110-8d53-11e4-9ef3-9503045c44e0.jpg',
  content: 'test',
  date: 'December 27, 2014',
  timestamp: '1419634934689',
  title: 'testtitle',
  __v: 0 }

Value: undefined

coverFilename obviously exists, so why is it undefined if I try to access it? I don't have a clue

1
  • does data returns an object? Commented Dec 27, 2014 at 9:49

1 Answer 1

1

With find, data is an array of matching objects, not just one. Use findOne instead of you only expect a single result.

Blog.findOne({date: 'December 27, 2014'}, function (err, data) {
    console.log("Data: " + data);
    console.log("Value: " + data.coverFilename);
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.