Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I thought I understood pub/sub in Meteor until I ran into this issue.
Suppose you have many blog entries that are meant for public consumption and a user navigates to /:blogId.
You use something like
Blogs.findOne(FlowRouter.getParam('blogId'));
Currently, on the server side, I'm publishing all blog entries.
Meteor.publish("blogs", function () {
return Blogs.find({});
});
I'm guessing I should only publish the blog entries that are requested with something like:
Meteor.publish("blogs", function (_id) {
return Blogs.find(_id);
});
What is best practice here?
You have it exactly right in your question:
Meteor.publish("oneBlog", function (_id) {
return Blogs.find(_id); // must return a *cursor* or array of cursors, not an object
});
Meteor.publish("allBlogs", function () {
return Blogs.find();
});
From the client subscribe to the oneBlog based on the route parameter:
Meteor.subscribe("oneBlog", FlowRouter.getParam('blogId'));
You can make another publication (which returns only one) for specific route.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I am new to QT and I want to know how I can get all the file names from a folder to a scroll area and allow the users to click on it to do a function.
I think you should read some documentation to understand how Qt works.
To get all files in directory, you can use entryInfoList() method of QDir. It is simple to use QListWidget to show this files.
You can create function to get files something like
QDir dir(path);
for (const QFileInfo &file : dir.entryInfoList(QDir::Files))
{
QListWidgetItem *item = new QListWidgetItem(file.fileName());
item->setData(Qt::UserRole, file.absolutePath()); // if you need absolute path of the file
listWidget->addItem(item);
}
If you don't want to use absolute path then you can use just entryList() method.
QDir dir(path);
for (const QString &filename : dir.entryList(QDir::Files)
listWidget->addItem(filename);
And connect to itemClicked() signal of QListWidget to do something when the user has clicked the entry.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I've seen a lot of examples online on how to write and read data to Firebase. However, I want to know how to write and read data from Firebase only created by logged in User.
How do we bind such data to a user?
Thanks
It might depend on how your data are oranized. Read through this:
https://firebase.google.com/docs/firestore/manage-data/structure-data
A simple example:
// snippet for pulling from data once it is there
await FirebaseFirestore.instance
.collection("USERDATA")
.doc(userID)
.collection('DOCUMENTS')
.get()
// one way you might supply the function that puts data up to firestore.
uploadToCloudStorage(
userID: user.fAuthUser.uid, fileToUpload: File(filePath));
Use the userId to as the docId for the documents in firebase. Here is an example.
createOrUpdateUserData(Map<String, dynamic> userDataMap) async {
FirebaseUser user = await FirebaseAuth.instance.currentUser();
DocumentReference ref =
Firestore.instance.collection('user').document(user.uid);
return ref.setData(userDataMap, merge: true);}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
I have an event from my Android app on Firebase that if it reaches a certain value I would like to be notified. Is this possible with Firebase?
Basically the event sends a string with what happened on a certain service request. If the service request failed it sends a certain string. I want to be alerted when that certain string is more than 10% of all events. How can I do that?
Thanks.
You can have a cloud function that is listing for events into the collection/doc you are interested in... when you get the error, you write to this collection lets say it is called WHATEVER_COLLECTION_YOUR_ARE_GOING_TO_LISTING_TO
It would look something like (i dont know your specific case, this is only to get you started):
import * as functions from 'firebase-functions'
import * as admin from 'firebase-admin'
const firestore = admin.firestore()
const counter = firestore.document(`WHATEVER_COLLECTION_YOUR_ARE_GOING_TO_LISTING_TO/{doc}`).onUpdate(async (change, _context) => {
const newData = change.after
const data = newData.data()
if (data.MYSTRING === 'SOMETHING HAPPENED IT IS MORE THAN 10%') {
// USE SENDGRID OR TWILIO OR WHATEVER TO NOTIFY ME
}
return Promise.resolve(true)
})
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I need to know the Technical Meaning of collection.allow() in Meteor JS.i had studied meteor document but not understand properly.So Can you please explain the below the terms with use of below code.
what is the doc?
How to check Posts.allow() is return true/false?
How to call the below methods like insert,update & remove when ever clicks a button?
How to write queries to insert , update & remove using the below methods in Meteor JS?
How to check more than one person allows to insert,update & remove queries?
Can you please give me suggestions about above things ?
Posts = new Meteor.Collection("posts");
Posts.allow({
insert: function (userId, doc) {
// the user must be logged in, and the document must be owned by the user
return (userId && doc.owner === userId);
},
update: function (userId, doc, fields, modifier) {
// can only change your own documents
return doc.owner === userId;
},
remove: function (userId, doc) {
// can only remove your own documents
return doc.owner === userId;
},
fetch: ['owner']
});
These methods are used to validate an insert/update/delete that the client requests. If the client calls Posts.insert(somePost). The server will use Posts.allow to validate if this can actually take place. To answer your questions directly:
what is the doc?
The doc in these methods is the document the client passes in. In my above example it would be somePost.
How to check Posts.allow() is return true/false?
Posts.allow() will check to see if a user can insert a post and return true if they can and false if they cannot (this is your responsibility). In your example there must be a valid userId and the document's owner must be the currently logged in user. Since your doc is a JSON object it must have an owners field in this example. If you always return false, then no client will ever be able to create a post. If you always return true, then any request to insert a post will be accepted.
How to call the below methods like insert,update & remove when ever clicks a button?
You actually never call these methods directly. They are called for you when the client attempts to insert/update/delete a Post.
How to write queries to insert, update & remove using the below methods in Meteor JS?
Again, you never actually call these directly, but when you do Posts.insert(somePost), it will automatically attempt to validate against the insert allow method. If it receives a true the post is inserted. If it receives a false it will throw an exception.
How to check more than one person allows to insert,update & remove queries?
Not exactly sure what you mean by this but if you have two people logged in and they both attempt to insert a post you can validate them uniquely given the userId field in the methods.
Update:
I'll elaborate on your comment's question. The document object just has an owner property on it. The document that is passed in may look like something like this (simplified):
doc = {
"name":"My Important Document",
"description": "This is a great document.",
"createdOn": 1394043417621,
"owner": b8QsgX3awg7E9DMKs
}
So doc.owner would give you the document's owner's id. You can then compare it to the userId passed in, to see if they are the same person.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I am parsing XML Document by using TBXML but I have to Parse XML and store data to SQLite asynchronously with notifications [that is Parsing and storing data in SQLite]. Please help me to overcome this problems. Thanks in advance....
For that You can use NSNotificationCenter and GCD,
First set NSNotificationCenter for your process using,
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(dataStore)
name:#"dataStoreComplete" object:nil];
- (void)dataStore
{
NSLog(#"Received Notification - Data stored in databse");
}
You GCD for parsing and storing in database
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// switch to a background thread and perform your expensive operation
// parse and store all data in sqlite,
dispatch_async(dispatch_get_main_queue(), ^{
// switch back to the main thread to update your UI
[[NSNotificationCenter defaultCenter] postNotificationName:#"dataStoreComplete" object:nil];
});
});