Access database values through plugin.
-
Hi,
In my plugin, I have used following piece of code to create entry into existing nodebb database and value gets stores into database.
var pid=4,
likecount = 1;
var data = {
pid:4,
ip:"0.0.0.0",
uid:0
}
db.setObject('like:'+pid+':'+likecount, data, callback);
It creates structure in database as "like
-> 4
-> like:4:1
pid:4
ip:"0.0.0.0
uid:0 "Can you please tell me, how to iterate each value from above structure using where clause.
For eg. Is that "like:4" contains specific ip address, It should iterate all the rows inside the "like:4" i.e 'like:4:1', 'like:4:2', 'like:4:3'.Any help would be greatly appreciated.
Thanks!!! -
Hi, I'm trying to understand what your objective is here, I'm learning newbie so puzzles like this help with that.
From what I can tell your trying to record the number of likes a user or something has?
Personally I think your storing the data wrong, your unique reference shouldn't be an IP address as this will change and you may have multiple users using the same IP.
What db are you using?
-
As @Huggy suggests, you should reconsider your database schema. Our database system doesn't work like a relational database, so you'll have to declare a data type that works with what you want to do later on down the line.
In the case of "likes" per pid, I would suggest that each pid maintain its own sorted set, with the timestamp of the like as it's score, and its value being the uid.
As mentioned prior, IPs can change and aren't reliable, so you should be looking to save via uid.
If you want to maintain a hash for each like, you can have it identified in the key (e.g.
like:{pid}:uid:{uid}
, or via a like idlike:{like-id}
) -
I am writing like plug-in, which provides an like functionality for anonymous as well as registered user.
1. Anonymous User should be able to like on any comment/reply and I have to restrict anonymous user via IP address.
Yet, I can store IP values to redis database, I need to find out, The given IP value is present in "like:pid" hash set.
I need to write query structure which finds out the given anonymous users IP address is not present in database for that particular post.Thanks!!