0

This code has the server insert some documents in a collection for the client to find it later.
I need to return the array for a given task But the page is saying

No data received

Why is that and how to fix it? Thanks

//Both
FooterButtons2 = new Mongo.Collection('footerButtons2');

//Server
Meteor.publish('footerButtons2', function(){
  return FooterButtons2.find();
});

FooterButtons2.insert(
  { "task1": ["submit"]},
  { "task2": ["cancel","continue"]}
);

//client
Meteor.subscribe('footerButtons2');
var res = FooterButtons2.findOne("task1");

1 Answer 1

1

When you search like this:

var res = FooterButtons2.findOne("task1");

you are searching an object that has the "_id" key equal to "task1", this is not correct. You want the object that has the key "task1" in it. The correct way would be:

var res = FooterButtons2.findOne({
    task1: { $exists: true }
});

But ideally, you should be doing searches based on values and not keys. Something like this:

FooterButtons2.insert({
    task: "task1",
    buttons: ["submit"]
}, {
    task: "task2",
    buttons: ["cancel", "continue"]
});

var res = FooterButtons2.findOne({
    task: "task1"
});
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.