3

I'm querying something simple from the database and it keeps returning me an empty array. I tried several ways following the documentation on the site.

user.chain().find({ email: 'test@gmail.com' }).data();

I tried this as well:

user.find({ email: 'test@gmail.com' });

I also added this before of course:

var user = db.addCollection('User', {
 indices: ['email']
});

I also tried it with the Dynamic View but it's not working neither.

Any Ideas? Thank you.

Mark
  • 1,603
  • 3
  • 13
  • 18

1 Answers1

2

I didn't know that you have to load the database before querying. Here is a simple example:

db.loadDatabase({}, function () {
 var user = db.getCollection('User');
 console.log(user.findOne({ 'email': 'example@gmail.com' }));
});

Hope it helps someone!

Mark
  • 1,603
  • 3
  • 13
  • 18