Query in Meteor-MongoDb

Hello fellow coders

I am trying to write a query to get a single entity from a collection , find or findOne is not working as I am getting all the documents in the collection when I query but when i write the same query through command prompt I am able to see that particular document.

import { Template } from 'meteor/templating’
import { Session } from ‘meteor/session’;
import { RegisterDetails} from '…/imports/api/registerdetails.js’
import ‘…/imports/ui/login.html’;
import ‘…/imports/ui/register.html’;

if (Meteor.isClient) {

Template.body.helpers({
showRegister() {
return Session.get(‘showRegister’);
}
});

Template.login.events({
‘click button’(event, data) {
var user = data.find("#usernameInput").value;
var pass = data.find("#passwordInput").value;
console.log(JSON.stringify(RegisterDetails.findOne(RegisterDetails.username)));

},
'click .js-show-register'(event) {
  event.preventDefault();
  Session.set('showRegister', true);
}

});

Template.register.events({
‘click button’(event, data) {
var firstname = data.find("#firstnameInput").value;
var lastname = data.find("#lastnameInput").value;
var username = data.find("#usernameInput").value;
var password = data.find("#passwordInput").value;
var repeatPassword = data.find("#repeatpasswordInput").value;
if(password === repeatPassword) {
var storePassword = password;
} else {
alert(“Password did not match”);
}
var role = data.find("#roleOption").value;

  if(storePassword) {
    RegisterDetails.insert({
      firstname,
      lastname,
      role,
      username,
      storePassword,
      createdAt: new Date()
    });
  }
},
'click .js-show-login'(event) {
  event.preventDefault();
  Session.set('showRegister', false);
}

});

}

As mentioned in the above code , I am trying to query the username and password field (shown in Bold and Italics).

Any help on this would be greatly appreciated

Thanks
Kartik

Snippet of the code

I am trying to query username and password fields

Please Help
Kartik

Are you sure that this is what you want to do?
For this to work, your client needs to have a subscription to the RegisterDetails collection - and would need every record in there. It looks like you’re trying to search a collection for the username input in the form. That will only work if the client has the entire collection local. (Unless I am misreading what you’re doing here).

It would be best to use Meteor.call() on the client with a Meteor.method() on the server to do the query.